|
|
02.10.10 Understanding Error handling In ColdBox By
Sean Corfield Since I spent quite a bit of time wrestling with this over the last week, I figured this blog post may help others. First off, a caveat: I'm running the latest version of ColdBox 3.0.0 from SVN which is "almost" Beta 4 and the details of error handling have changed a little over the last few Betas (for the better). ColdBox provides a number of ways to handle different types of errors. I'll cover the following options:
• onMissingAction
• onInvalidEvent • ExceptionHandler • onException • MissingTemplateHandler onMissingAction This is a method on your event handler CFC that is executed if the requested event identifies your handler but does not match a declared public method. This is helpful when you want to respond dynamically to certain requests, e.g., /page/about-us where Page.cfc will look up the action in a database to display certain "static" content – a mini-CMS, in other words. You could of course use /page/display/content/about-us and have a regular event handler that looks up the content but that's an uglier URL with essentially the same handler method. You can't (shouldn't) use this to try to catch invalid event requests – you'd need it in every handler and it still wouldn't catch request like /bogus/stuff where no handler Bogus.cfc is present. That's what onInvalidEvent is for. onInvalidEvent This is a Setting in your ColdBox XML file that identifies an event handler, e.g., "Sorry.pageNotFound", that should be executed if a request is made either for an action that doesn't exist on a handler (and which doesn't have an onMissingAction() method) or for a handler that doesn't exist. A couple of things to be aware of:
• When your invalid event handler is executed, the view for the original (invalid) event has already been set. This means you probably need to explicitly set the view you want – event.setView( 'page/notfound' ) – because if the event requested was invalid, there's probably no such view.
• The invalid event name is passed into your handler in the private request context so you need to supply an additional argument to getCollection() or getValue(): var prc = event.getCollection( private = true );> or event.getValue( name = 'invalidEvent', private = true ). In Beta 3, the 'invalidEvent' key was stored in the (public) request context (although it wasn't always there). ExceptionHandler Continue reading this article. About the Author: Sean is currently Chief Technology Officer for Railo Technologies US. He has worked in IT for over twenty five years, starting out writing database systems and compilers then moving into mobile telecoms and finally into web development in 1997. Along the way, he worked on the ISO and ANSI C++ Standards committees for eight years and is a staunch advocate of software standards and best practice. Sean has championed and contributed to a number of CFML frameworks and was lead developer on Fusebox for two years. |
|
|
|
|
-- coldfusionpronews is an iEntry, Inc. publication -- iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 2010 iEntry, Inc. All Rights Reserved Privacy Policy Legal archives | advertising info | news headlines | free newsletters | comments/feedback | submit article |