onException problem (CB 2.6)

I am struggling with a minor issue in CB 2.6, and I’m certain that I am missing something really simple.

I simply want to trap any exceptions and perform two things:

  1. Display a view, within a layout, that advises the user that an error has occurred, and that the system administrator has been notified.

  2. Shoot an email to the administrator with details regarding the error as exposed in the exceptionBean.

I have added an onException setting to the ColdBox.xml.cfm pointing to the onException handler in main.cfc (main.onException). The onException event is being fired, however, I can’t seem to get the message to display within a layout. The view does display, however, it is almost like there is a noLayout being invoked.

Anyone know what I’m missing?

Kevin S. Anderson

Superlative Solutions, Inc.

Can you post your onException method? Do you have a defaultLayout set, or are you setting on in the handler?

For what it’s worth, my “Call Customer Service” page is a stand-alone cfm page and I redirect to it. The onError method in my Application.cfc also points there. That way I am guaranteed my user’s will see a pretty message, even if ColdBox itself is blowing chunks and can’t get initialized. The stand-alone page doesn’t require ColdBox, or the database to run.

Thanks!

~Brad

Thanks, Brad:

Following is the “simple” form that doesn’t have a lot of stuff in it. I’ve also tried doing setNextEvent() persisting the exceptionBean but that seems to be ignored.

//Grab Exception From request collection, placed by ColdBox

var exceptionBean = event.getValue(“ExceptionBean”);

//Place exception handler below:

var rc = event.getCollection();

rc.exception = exceptionBean;

event.setView(“misc/generic_error”);

if( structKeyExists(client, “isLoggedIn”) AND client.isLoggedIn ) {

event.setLayout(“Layout.Store”);

} else {

event.setLayout(“Layout.Public”);

}

Kevin

Hi Guys,

Here is some clarification, sometimes hidden in the docs.

When you use the exception handler or the onException interceptor, the flow is the following:

→ Execute event
→ If error occurrs then

  • Throw onException interceptor
  • Throw exception handler
  • Present either the custom error template or the generic error template

This means that the exception handler and onException interceptor are atomical executions after an exception. Rendering will not happen like normal after those handlers execute, because the framework has detected something invalid. If you do nothing after these handlers, the framework will render out the generic error handler or your own custom error handler.

Therefore from your custom error template you can decide what will be rendered. That is what I advise, and if not, then just relocate via setNextEvent() to somewhere you need to send them.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com