Home

Post

Feeds

RSS

Apr 22Catching Java Exceptions In ColdFusion

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.

Posted by: Andrew Powell

Categories: Java , ColdFusion , General , Universal Mind

Write your comment



(it will not be displayed)







About Andrew Powell

More ...

Powered by Mango Blog: a ColdFusion blog engine