0

Error Handling in CFSCRIPT

ColdFusion
I seem to find myself slowly moving more and more towards using cfscript wherever I can.  I can often create the same end result in fewer lines.  Plus, the code that I am writing is much more in line with other languages.  The problem is when you get down in the cfscript and realize there is no script equivalent for the CF tag you would normally use at a certain point in your logic.  This holds true with <CFTHROW>.  In MX, Macromedia did provide the ability to do try(s) and catch(s).  The one thing they left out (unless I simply can't find it) was including a throw.  Seems obvious enough huh?

Well, in case you haven't thought of this pretty obvious solution, I take the approach of adding the following function in my application base classes so that other classes that extend the base class can use it too:


<cffunction name="throw" output="false" returntype="void" access="public">
 <cfargument default="" type="string" name="message" />
 <cfthrow message="#arguments.message#" />
</cffunction>

Now, anywhere you need it you can just use:
 throw("This is my big error message!");
tags:
ColdFusion

Search

Dave at work...