BackUp LevelNext

Overview of Exception Handling in ColdFusion

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, or developer-specified events.

You use the following syntax for CFTRY/CFCATCH blocks:

<CFTRY>
... Add code here ...

    <CFCATCH TYPE="exception type">
    ... Add exception processing code here ...
    </CFCATCH>

    ... Additional CFCATCH blocks go here ... 
</CFTRY>

In order for ColdFusion to handle an exception, it must appear within a CFTRY block. You might enclose an entire application page in a CFTRY block, using a CFCATCH block around a potential error.

To catch errors in a single problematic SQL statement, for example, you might narrow the focus by using a CFTRY block with a CFCATCH TYPE="Database" tag, outputting the CFCATCH.State information as well.

See the CFML Language Reference for information on the CFTRY, CFCATCH, and CFTHROW tags.

Types of recoverable exceptions supported

The ColdFusion Server supports several types of recoverable exceptions. Use the TYPE attribute in the CFCATCH tag to determine which type of exception to catch.

Application-defined exception events

ColdFusion applications can raise exceptions using the CFTHROW tag, with an optional diagnostic message. CFTHROW raises an exception that can be caught by a CFCATCH TYPE="Application" tag, or a CFCATCH TYPE="Any" tag. This exception can also be caught by a CFCATCH block that has no TYPE attribute.

Database failures

Use the CFCATCH tag with TYPE="Database" or CFCATCH TYPE="Any" to catch failed database operations, such as failed SQL statements, ODBC problems, and so on.

Template errors

Use the CFCATCH tag with TYPE="Template" or TYPE="Any" to catch general application page errors.

Missing included file errors

Use the CFCATCH tag with TYPE="MissingInclude" or TYPE="Any" to catch errors for missing included files.

Object exceptions

Use the CFCATCH TYPE="Object" tag to catch exceptions in ColdFusion code that works with objects.

Security exceptions

Use the CFCATCH TYPE="Security" tag to raise catchable exceptions in ColdFusion code that works with security.

Expression exceptions

Use the CFCATCH TYPE="Expression" tag to catch exceptions when an expression fails evaluation.

Locking exceptions

Use the CFCATCH tag with TYPE="Lock" to catch failed locking operations, such as when a CFLOCK critical section times out or fails at runtime.

Unexpected internal exceptions

You can catch unexpected exceptions in the ColdFusion Server with the CFCATCH TYPE="Any" tag.

Note

Attempting to handle unexpected exceptions in CFML code can cause unpredictable results, and may seriously degrade or crash the ColdFusion Server.


BackUp LevelNext

allaire

AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.