Exception Types In CFCatch Blocks Do Not Have To Be Quoted

This is a really minor post, but this morning, I made a small syntax discovery regarding ColdFusion's CFTry / CFCatch statements - the error types do not have to be quoted. This is true even if the type contains a dot-delimited hierarchy. Here's a quick example:

<cfscript>

try {

throw( type = "Foo" );

} catch ( "Foo" error ) {

writeOutput( "Caught Quoted: #error.type# <br />" );

}

try {

throw( type = "Foo.Bar" );

} catch ( "Foo.Bar" error ) {

writeOutput( "Caught Quoted: #error.type# <br />" );

}

// ------------------------------------------------------ //

// Type value not quoted in CFCatch.

// ------------------------------------------------------ //

try {

throw( type = "Foo" );

} catch ( Foo error ) {

writeOutput( "Caught Unquoted: #error.type# <br />" );

}

try {

throw( type = "Foo.Bar" );

} catch ( Foo.Bar error ) {

writeOutput( "Caught Unquoted: #error.type# <br />" );

}

</cfscript>

Notice that the type in the Catch block is only quoted in the first two Try/Catch statements, but not in the second two. When we run the above code, we get the following output:

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments

Live in the Now

Oops!

Name:

Email:

( I keep this private )

Website:

Comment:

Subscribe to comments.

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please
do not post unrelated questions or
large chunks of code. And, above all, please be nice to each other - we're trying to
have a good conversation here.

I am the co-founder and lead engineer at InVision App, Inc — the world's leading prototyping,
collaboration & workflow platform. I also rock out in JavaScript and ColdFusion 24x7 and I dream about
promise resolving asynchronously.