Blog

Bypassing ColdBox's Error Handling

Brad Wood April 10, 2015

Spread the word

Brad Wood

April 10, 2015

Spread the word


Share your thoughts

Error handling is one of those important things that many developers neglect.  Your code never errors once you're done testing it, right :) ColdFusion's detailed error messages were always a draw to the platform, but have become a bit of an embarrassment when surfing across a site that's sporting the default, ugly error page because the developers didn't bother to even implement a global error handler. 

When you use ColdBox, errors in your code are handled automatically by the platform.  There are very few features of ColdBox that kick in by default but this is one of them and we feel it's for very good reason.  ColdBox's debugging screen is not only prettier, but it displays a plethora of additional information to help you troubleshoot.  In ColdBox 4, we took it a step further by making ColdBox's default error template secure-by-default.  This means if you install ColdBox, don't change a single setting, and push it to production, errors on your site won't be advertised in juicy detail to the first hax0r that surfs across.

ColdBox's error handling is also incredibly powerful.   There's no need to litter your code with try/catches to ensure all errors are handled.  The framework will capture any error and gives you several ways of handling that error, whether it's the onError() convention in your handler, the exception handler event, or an interceptor.  Take your pick.  You can read about all these options here.

http://wiki.coldbox.org/wiki/ExceptionHandling.cfm

Perhaps surprisingly, this blog isn't about any of those options.  I wrote this up to describe how to completely BYPASS ColdBox's exception handling.  I've only heard one person ever want to do this, but they suggested that perhaps others had wondered the same thing and simply not voiced the question.  Honestly, I'm not sure why you'd want to bypass a perfectly good, extensible error handling subsystem to write another one from scratch, or just leave your site unsecured, but I suppose it's possible you just really like the colors of the default error template.

To cause your exceptions to bubble up out of the framework, simply put this bit of code in your /config/ColdBox.cfc somewhere outside of the configure() method.

function onException() {
  throw( object=interceptData.exception);
}

Yep, it's really that simple.  The magic that lets this work is the fact that your ColdBox configuration file itself gets registered as an interceptor.  This means you can create interceptor methods right there in your config file and they'll get registered.  In this case, we're listening to the onException interception point, then simply re-throwing the exception object.  This will promote the exception up to your Application.cfc's onError() method, or if that isn't defined, the global error template defined in your CF Administrator.

 

Add Your Comment

Recent Entries

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Unfortunately, we often hear this message from clients who thought it would never happen to them... until it did. Some believed they could delay the expense of Implementing ColdFusion security best practices for one year, while others were tempted to put it off for just a few months. However, in today's rapidly evolving digital landscape, the security of web applications, including ColdFusio...

Cristobal Escobar
Cristobal Escobar
April 16, 2024
Ortus March Newsletter

Ortus March Newsletter

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
April 01, 2024
Into the Box 2024 Last Early Bird Days!

Into the Box 2024 Last Early Bird Days!

Time is ticking, with less than 60 days remaining until the excitement of Into the Box 2024 unfolds! Don't let this golden opportunity slip away; our exclusive Early Bird Pricing is here for a limited time only, available until March 31st. Why wait? Secure your seat now and take advantage of this steal!

Maria Jose Herrera
Maria Jose Herrera
March 20, 2024