Pete Freitag Pete Freitag

CFCatch Java Exceptions

Published on June 12, 2009
By Pete Freitag
coldfusionjava

Did you know that you can catch java exceptions by class name with cfcatch? It's not documented on the cfcatch tag documentation (as of CF8), but it works... Here's an example:

<cftry>
 	<cfset list = CreateObject("java", "java.util.LinkedList")>
 	<cfset list.get(5)>
 	<cfcatch type="java.lang.IndexOutOfBoundsException">
  		Index outta bounds
 	</cfcatch>
</cftry>

There is one special exception that Mark Mandel has blogged about, and that is if the exception is caused by a class that was loaded by a different classloader, cfcatch won't be able to catch it by type. Perhaps that's why this feature is undocumented?



java cfcatch exception

CFCatch Java Exceptions was first published on June 12, 2009.


Fixinator

The Fixinator Code Security Scanner for ColdFusion & CFML is an easy to use security tool that every CF developer can use. It can also easily integrate into CI for automatic scanning on every commit.


Try Fixinator

CFBreak
The weekly newsletter for the CFML Community