[ColdBox 3.5.2] Exception "handling" weirdness

Does ColdBox do something “odd” with its exception handling out of the box? Where “odd” is “do anything with an exception other than simply let it bubble back to ColdFusion”.

Why I ask, is I have this code in one of my handler methods:

throw “exception0”;

var myVar1 = modelObject1.callToMethod();
throw “exception1”;

var myVar2 = getModel(“modelClass2”).callToMethod();
throw “exception2”;

throw “exception3”;

And what I get back in the CB exception-handling output is:

Note that it is getting past exceptions 0 & 1, but raising exception 2.

If I change the code slightly to be this:

throw “exception0”;

var myVar1 = modelObject1.callToMethod();
throw “exception1”;

Then I get nothing on the screen.

If I change it to this:

throw “exception0”;
var myVar1 = modelObject1.callToMethod();

I then get exception0 being raised.

My config is fairly bog standard, and I have no settings to the effect of “screw with how exceptions are dealt with”. I’ve not got anything to do with exception-handling in there at all, that I can see. This would have me assume there would be no special exception handling being done, and any exceptions beign raised would just… error.

I am 90% certain I am not missing something obvious with my code, and accordingly 90% certain CB is “helping” with something it oughtn’t be “helping” with (given I’ve not asked it to). But am happy to be wrong on this.

Oh: I am in the process of troubleshooting a problem with modelObject1.callToMethod() - I know something is wrong with it - and it’s whilst troubleshooting this I’ve come across this weirdness. However for all intents and purposes the code within the methods will definitely (?) not be contributing to what I am seeing.

I’m guessing it’s something “obvious” in my config I am not aware of (which makes it hard to google answers for… “help with the thing I don’t know what it is” :wink:

Cheers for any insight.


That does sound very weird, now I have a question because I am wondering if the same example works in a standard component outside of ColdBox?

Hi Andrew.
Yeah, the CFML works exactly as one would expect if not in the context of ColdBox. I did not completely decouple everything so as to run exactly the same code, but ran a facsimile thereof.

Why I suspect CB is monkeying with things is that I’m getting that CB-specific error screen, not the CF one. So it’s definitely intercepting exceptions… just not then handling them in a fashion that makes sense (to me. At the moment).

Cheers for looking at this.

Yes it is messing around with the exceptions, but maybe not the way you think. There are a number of different ways ColdBox catches them, which is dependent on whether it is a handler exception, missing method to name a few. And of course if you have the onError() in the Application.cfc or even an interceptor being notified of an exception.

I was sort of assuming you had that code in the same script block, because it should still adhere to that logic flow and why it doesn’t make sense.

Those are consecutive lines of code in the handler method, and I’ve omitted nothing between the first and last lines I quoted.

I would have thought that unless I’d specifically configured it otherwise, CB would just rethrow any exceptions? I mean fair enough for it to have onMissingTemplate() and onError() handlers, but the default behaviour of those should just be a rethrow?

I’m not at the computer with my code on it at present, so can’t give you any further info @ the mo’,

I think, it has to do with 'var' variables being hoisted to the top of the function.

CF will be first create the 'var' variables, and then start executing the rest of the code.

I don't have a computer to test this, but maybe you're on the right path with this?!

Cheers Rainer.

It’s JS that does hoisting mate, not CF.

That said, I’ll remove all doubt and try it (and report back).

You're so right, CF does not hoist.

Phew. You actually had me worried there for a sec. For all the emphaticness (to invent a word) of my answer previously, it occurred to me I didn’t actually know CF didn’t do that… I’d just assumed it wouldn’t’ve, and had never seen a symptom of it happening. But that might have been good luck rather than good management.


Brad, you asked me about interceptors and stuff on Twitter. I’ve not done anything specific for error handling, hence my surprise anything other than default behaviour was occurring. My Coldbox.cfc is here: https://gist.github.com/4414194

The only interceptor I have configured is for security. And that stuff I pretty much copied from the docs somewhere. It’s a very bare-bones app. The security stuff works fine, and I would not think it would have any impact on exception handling?

Thanks mate.