noob: exception handling help needed

Sorry for repeating this question. Since there have been no responses it might not be very well explained. I have tried to be more concise here.
We are migrating to CF9 and CB 3M5 (never previously having used a framework). We have a number of existing custom tags. One tag we want to call on every single request. I created a **preProcess interceptor** to do just that. This tag currently checks for some specific things, and, depending on what it finds, writes to a table and relocates to an error page. I’ve done a bit of modification to this, but could not get it to show the error page decorated with my layout. So, I thought I should have the custom tag throw an error when called from CB (indicated by an attribute) and have the exception handler take over. The exception handler is set to point to Main.onException(). I then have a switch on the exception, just as I’ve seen from in the documentation, and I case for my specific type. I can see that I execute the appropriate case statement, but I still do not get my view decorated even though I am using **event.seView(‘myErrorView’)**. Instead, I get the standard **Oops** page. Upon closer reading of the documentation, this is the expected behavior. It indicates that I could set a **CustomErrorTemplate**. From what I can tell, that all my errors (exceptions) would use this same template. This is not what I want. I want to have a variety of error pages. We have a number of custom tags that each displaying different messages. And, I want all of them decorated with the layout. Any suggestions on how to achieve my desired end result? 

One option is to redirect. You can create a handler like
"errormessages" that does not have any dependencies. It's simply a
dumb handler that displays your error html views.

Then, in your onException case, you'd simply redirect to the appropriate view.

case 1: setNextEvent("errormessages.msg1")
case 2: setNextEvent("errormessages.msg2")

What I like about redirection is that if a user gets an error, they do
not remain on the same page that errored out.

- Gabriel

I’ve been struggling with this since your post. I changed the event handler to go to my new CFC and method called alert. Everything seems fine until I call setNextEvent. I keep getting exception EventHandlerNotRegisteredException. I have the code below, along with my debug output. As you can see, I have the method in question defined. Oddly enough, because this exception gets thrown, it gets redirected to the alert method and falls through to the default case, and then redirects to the default method without a problem. I have tried many, many things to resolve this or isolate the issue. I keep coming up empty and have exhausted my knowledge. Any ideas?

I am wondering, too, is there a way to see a list of the registered event handlers?



var rc = event.getCollection();

//Grab Exception From request collection, placed by ColdBox

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

logger.debug("alert: exceptionBean.getType() is " & exceptionBean.getType());

logger.debug("alert: cgi.QUERY_STRING is " & cgi.QUERY_STRING);

switch ( exceptionBean.getType() ){

case “dataInvalid”:

logger.debug(“alert: case=dataInvalid”);




logger.debug(“alert: case=default”);




var rc = event.getCollection();

rc.pageTitle = " → Invalid Data Error";



//Grab Exception From request collection, placed by ColdBox

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

logger.debug(“default: testing for exception bean existence”);

if (isDefined(‘exceptionBean’)) {



var rc = event.getCollection();

rc.pageTitle = " → Error";


The custom "exceptionHandler" is special. Try redirecting to a another
handler that is used to display your views instead of trying to have
the exceptionHandler display views as well. That may be causing the

In other words, when you're ready to redirect, do so to a plain old
handler. Looking at your code, "dataInvalidError" and "default" would
be moved to this handler whose responsibility would be to display all
of your different messages.

- Gabriel

Thanks for getting back to me so quickly. If I understood properly, then the change did not work. I moved my case logic back into Main.onException and changed the config accordingly. Main.onException does a redirection to ErrorHandler (routed to error, though this does not seem to be part of my problem as I tried specifying the actual vs routed name).

I am still lost. Why is it redirected to Main.onException twice? I suppose because of the EventHandlerNotRegisteredException that is thrown by the framework. But, why is this thrown when it is not thrown when redirected to default? This does not make any sense to me at all.


[COMMENT: page submitted and is intercepted preprocess]


[COMMENT: the query string is tested to determine if the validation should occur. It does not contain error, so yes it should]

“DEBUG”,“fileLog”,“06/22/2010”,“13:15:52”,“owners.model.interceptors.dataValidation”,“preProcess: findNoCase(’=error.’, cgi.QUERY_STRING) is 0”

[COMMENT: the actual contents of the query string within the pre-process interceptor]

“DEBUG”,“fileLog”,“06/22/2010”,“13:15:52”,“owners.model.interceptors.dataValidation”,“preProcess: cgi.QUERY_STRING isid=1%27%20or%201%20=%201”

[COMMENT: a custom exception was thrown so the process is redirect to Main.onException]


“DEBUG”,“fileLog”,“06/22/2010”,“13:15:52”,“owners.handlers.Main”,“onException: cgi.QUERY_STRING is id=1%27%20or%201%20=%201”

[COMMENT: the dataInvalid case is taken and the process is redirected to error.dataInvalidError]

“DEBUG”,“fileLog”,“06/22/2010”,“13:15:52”,“owners.handlers.Main”,“onException: case dataInvalid”

“DEBUG”,“fileLog”,“06/22/2010”,“13:15:52”,“owners.handlers.Main”,“onException: exceptionBean.getType() is dataInvalid”

[COMMENT: I guess it makes sense that it would traverse the interceptor again]


[COMMENT: the query string is tested to see if it is an error page being displayed]

[COMMENT: it is, so the offending logic that caused the exception is not executed again]

“DEBUG”,“fileLog”,“06/22/2010”,“13:15:52”,“owners.model.interceptors.dataValidation”,“preProcess: findNoCase(’=error.’, cgi.QUERY_STRING) is 1”

[COMMENT: Why am I back here? Shouldn’t it be in error.dataInvalidError???]

[COMMENT: Apparently error.dataInvalidError is not registered]


“DEBUG”,“fileLog”,“06/22/2010”,“13:15:52”,“owners.handlers.Main”,“onException: cgi.QUERY_STRING is =error.dataInvalidError”

[COMMENT: EventHandlerNotRegisteredException is not handled by the case, so default executed]

“DEBUG”,“fileLog”,“06/22/2010”,“13:15:52”,“owners.handlers.Main”,“onException: case default”

“DEBUG”,“fileLog”,“06/22/2010”,“13:15:52”,“owners.handlers.Main”,“onException: exceptionBean.getType() is HandlerService.EventHandlerNotRegisteredException”

[COMMENT: Redirecting causes traversal of the interceptor again]


[COMMENT: Odd… Where did the query string go? It had been redirected to error.default]

“DEBUG”,“fileLog”,“06/22/2010”,“13:15:53”,“owners.model.interceptors.dataValidation”,“preProcess: cgi.QUERY_STRING is”

[COMMENT: The query string test doesn’t match, but the data causing the error is gone too]

[COMMENT: No exception gets thrown]

“DEBUG”,“fileLog”,“06/22/2010”,“13:15:53”,“owners.model.interceptors.dataValidation”,“preProcess: findNoCase(’=error.’, cgi.QUERY_STRING) is 0”

[COMMENT: Finally it is in the default method and the default error screen is displayed]


“DEBUG”,“fileLog”,“06/22/2010”,“13:15:53”,“owners.handlers.ErrorHandler”,“default: testing for exception bean existence”

Oh, and if I just enter
into the address bar, I get the desired page displayed without the
EventHandlerNotRegisteredException being thrown.

That is strange. What version of CB are you running? What CF engine?

If you can, attach your code to the thread and I'll try to run it and
see what I get.

- Gabriel