Click to Play

Digittronics Exhibits Cool RCX4
If you're a fan of flying helicopters, or Star Wars for that matter, you are going to love the RCX4 Star Stryker from Digittronics. WebProNews caught up with Patrick Le...

Recent Articles

How To Improve Your CFSCRIPT
One of the new features in Adobe's ColdFusion 9 release that has excited a lot of developers is the broad range of enhancements to CFML's "other" language: CFSCRIPT.

Why Static Methods For ColdFusion Fail
This cropped up on the TDD mailing list and it made me smile so I wanted to share it along with some commentary. A fairly common request from folks...

Installing Coldfusion 9 On Your Windows 2008 Server
This blog is slowly turning into a ColdFusion site it seems :-) Blame ColdFusion for that, it's the one...

Hal Helms Officially Leaves Coldfusion
About two weeks ago, Hal Helms blogged that he is leaving ColdFusion for Ruby on Rails. Naturally it stirred a lot of the traditional "is ColdFusion dead?" worrying...

New Updates For cf.Objective 2010 Conference
The Content Advisory Board (twelve of last year's speakers) have just finished their initial selection of topics and potential speakers for the four tracks...


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.
About ColdFusionProNews
ColdFusionProNews is a collection of news and commentary designed to keep you in step with the ever evolving landscape of ColdFusion environments. News and Advice for ColdFusion Professionals





ColdFusionProNews is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITmanagementnews.com





 
-- 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


WebProWorld Forum eCommerce Trends Become Strategy