• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 9. Error and Exception Handling > Custom Exception Handling

9.2. Custom Exception Handling

In the previous section, we covered the basics of using CFTRY/CFCATCH to handle predefined types of exceptions that might occur within a ColdFusion application. While these general exception types can handle any type of exception, they do so in a generic, one-size-fits-all manner. Fortunately, ColdFusion also allows you to specify custom exception types that can be caught with the same CFTRY/CFCATCH techniques we already covered.

As I mentioned in the previous section, the CFCATCH tag can accept a custom exception type for its TYPE attribute. That custom exception type is defined using the CFTHROW tag. The CFTHROW tag generates a custom exception type that can be caught by a CFCATCH tag when the TYPE attribute is set to Application, Any, or the custom type you specified in the CFTHROW tag. In other words, when something goes wrong in your application, and you need to generate a custom exception, use CFTHROW. The general syntax for using CFTHROW is as follows:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint