ColdFusion 9: cfscript DOES support rethrow!

In a conversation that came up during a meeting today, there was some discussion as to whether or not ColdFusion 9's beefed-up CF Script support included rethrow. Next thing you know a few of us dash off to test it.

Turns out it supports it as a statement. Also turns out that it's not mentioned in the ColdFusion 9 documentation, at least not in the sections that act as documentation for CF Script. Sadly, the whole CF Script section of the Developer's Guide kinda sucks and in the language reference (actually referred to as the CFML Language Reference) it's not mentioned outside the tag, and that just has a link to the Developer's Guide.

Blog time! So...

It works. And I also discovered a way of using it that I'd never thought of before. If you have a catch statement that does some things like logging or an alternate behavior or something, but then you want to return the flow to the built-in error handlers, you can do it like this:

view plain print about
1<cfscript>
2    try {
3        if (a==1) b=2;
4    } catch (any a) {
5        writeDump(var=a);
6        rethrow;
7    }
8
</cfscript>

I've only ever used it in CFCs where I was going to have deep composition and I wanted to be sure that a particular error was going to be the one that was seen. It changes where the error gets reported from, locally where the code is executing or from the caller's perspective. Without rethrow, the error will usually be reported from the caller's perspective instead local to the running code.

Happy throwing...

Laterz!

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Very cool find. KUDOS amigo.
# Posted By John Farrar | 1/31/11 5:33 PM
Actually, it *is* mentioned in the CF9 docs. http://help.adobe.com/en_US/ColdFusion/9.0/Develop...
# Posted By Matt Quackenbush | 1/31/11 5:41 PM
Interesting, Matt...

Here's the thing: I use the local versions of the documentation. Almost exclusively. Especially the help files baked in to CF Builder. I looked where I'm used to looking. :)

It's nice to know that it's been added to a later version of the documentation, so I suppose I should revise my statement to be something like:

"The Adobe documentation DIDN'T ORIGINALLY include any reference to cfrethrow..."

Interestingly the comments at link you gave continued to point out things that were missing in that list. Curious...
# Posted By Jared Rypka-Hauer | 1/31/11 5:48 PM
Ahh. I quit looking at the local docs many years ago because of the fact that there are simply too many instances where the live docs contain updated/corrected info (if only in the comments).
# Posted By Matt Quackenbush | 1/31/11 5:56 PM
I wonder if it was added in Updater 1 ? That seems to be why teh storeSetAcl and storeGetAcl functions are also missing.

I also use the online docs whenever I can - bound to be more up to date.
# Posted By Tom Chiverton | 2/1/11 1:01 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.7. Contact Blog Owner