<CFTRY>
... Add code here
<CFCATCH TYPE="exceptiontype">
... Add exception processing code here
</CFCATCH>
... Additional CFCATCH blocks go here
</CFTRY>
Used with one or more CFCATCH tags, the CFTRY tag allows developers to catch and process exceptions in ColdFusion pages. Exceptions include any event that disrupts the normal flow of instructions in a ColdFusion page such as failed database operations, missing include files, and developer-specified events.
TYPE
Optional. Specifies the type of exception to be handled by the CFCATCH block:
- Application
- Database
- Template
- Security
- Object
- Synchronization
- MissingInclude
- Expression
- Lock
- Any (default)
Usage
You must code at least one CFCATCH tag within a CFTRY block. Code CFCATCH tags at the end of the CFTRY block. Always code CFCATCH TYPE="ANY" last; ColdFusion tests CFCATCH tags in the order in which they appear in the page.
Applications can optionally use the CFTHROW tag to raise custom exceptions. Such exceptions are caught with either TYPE="APPLICATION" or TYPE="ANY".
The tags that throw an exception of TYPE="TEMPLATE" are CFINCLUDE, CFMODULE, and CFERROR.
An exception raised within a CFCATCH block cannot be handled by the CFTRY block that immediately encloses the CFCATCH tag.
You can use the CFCATCH variable to access exception information:
- Type -- Exception type, as specified in CFCATCH
- Message -- The exception's diagnostic message, if one was provided. If no diagnostic message is available, this is an empty string.
- Detail -- A detailed message from the CFML interpreter. This message, which contains HTML formatting, can help determine which tag threw the exception.
- NativeErrorCode -- TYPE=Database only. The native error code associated with this exception. Database drivers typically provide error codes to assist diagnosis of failing database operations. If no error code was provided, the value of NativeErrorCode is -1.
- SQLState -- TYPE=Database only. The SQLState associated with this exception. Database drivers typically provide error codes to assist diagnosis of failing database operations. If no SQLState value was provided, the value of SQLState is -1.
- ErrNumber -- TYPE=Expression only. Internal expression error number.
- MissingFileName -- TYPE=MissingInclude only. Name of the file that could not be included.
- LockName -- TYPE=Lock only. The name of the affected lock (set to anonymous if the lock was unnamed).
- LockOperation -- TYPE=Lock only. The operation that failed (set to Timeout, Create MuteEx, or Unknown).