Wednesday, March 25, 2009

Try/Catch in OnError function of Application.cfc

So you're stoked that you switched to application.cfc and you wont have to see those hard ColdFusion errors since app cfc has the OnError function? Sorry to bust your bubble, but what if your OnError function throws an error(referencing a variable that isn't present for example)? Then what? That's right, a hard ColdFusion error will be shown and hopefully you were smart and turned off the Robust Exception option in the ColdFusion Administrator! :)

To remedy this situation you could add in a try/catch block right there in the OnError function. A more generic process could be put in the catch block that perhaps should never throw an error, something very simple that doesn't reference any variables that may not be present.

1 comment:

  1. quote: "Sorry to bust your bubble, but what if your OnError function throws an error(referencing a variable that isn't present for example)? Then what? That's right, a hard ColdFusion error will be shown and hopefully you were smart and turned off the Robust Exception option in the ColdFusion Administrator! :)"

    - actually, this is why you always want a Server-wide Error-handler defined in your CF Admin. No type of CF error can get past it, assuming there are no errors in the error-handler template itself. You want to put a try/catch around any block of code in your error-handling that could ever possibly break (tip: certain CF scopes, such as FORM, URL, session, and others aren't even defined in Event Gateways for example, so your error-handling can never assume it can just cfdump them in an email and send them to you)

    ReplyDelete