When you are using custom java objects in your ColdFusion code, often times these objects will throw custom exceptions. These exceptions, like all others, should be handled gracefully. So how do you listen for custom java exceptions in ColdFusion? Let's consider the exception "java.lang.NullPointerException". We can listen for this specific type of exception with the code below:
<cftry>
<!---
some operation on your java object
--->
<cfcatch type="java.lang.NullPointerException">
<!--- error handling code --->
</cfcatch>
</cftry>
Since java.lang.NullPointerException extends java.lang.Exception, you could easily swap the two in the type attribute of CFCATCH and get the same results. So if you are working with Spring and/or Hibernate, this makes it easier to catch and handle exceptions that you may come across in your java code.























0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment