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

ColdBox 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023