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:

<cfthrow type="custom_exception_type"

The cfthrow tag accepts the following optional attributes:


Specifies a name for the exception type. You may give the exception type a custom name or use the predefined type Application.


Message describing the event that triggered the exception.


Specifies additional information about the exception.

errorcode ...

Get Programming ColdFusion MX, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.