Understanding Errors and Exceptions


An error is defined as a problem that occurs when ColdFusion interprets a template and executes ColdFusion tags. The error stops the processing of the template and logs it in the ColdFusion application log file. Errors can occur due to incorrect syntax, invalid data entry, missing files, lack of memory, and so on. While some errors can be recovered, others cannot. The recovery of an error depends on its cause. For example, errors resulting from missing templates or time-outs cannot be recovered. On the other hand, if data has been entered in a form incorrectly, the end user can be notified to reenter the correct data.

Types of Errors

ColdFusion errors can be classified as follows:

  • Missing template. This error is generated when a browser requests a CFML page that doesn't exist. You can specify a missing template handler page in ColdFusion Administrator to avoid displaying the standard error message.

  • Form field data validation. This error is generated when end user data doesn't meet the server-side form validation rules. You can use the <cferror> tag to handle this error and avoid displaying the standard error message.

  • Exception. This error prevents the continuation of normal processing. Exceptions can occur during compilation (for example, syntax errors) or runtime (system or logical errors). You can use the <cftry>, <cfcatch>, <cfthrow>, and <cfrethrow> tags to handle exceptions.

Caution

Compile time exceptions occur before the ColdFusion page is converted to executable code. As a result, they cannot be handled on the page that causes them.

Types of Exceptions

Exceptions can be predefined or custom types. You can define custom type exceptions and handle them the same way you handle the predefined ones. Exceptions in ColdFusion can be classified as follows:

  • Database. This exception is used when a database operation fails. For example, a syntax error occurs when you attempt to connect to a database, or when there are ODBC problems such as a missing support driver.

  • Template. This includes general application page errors, such as invalid tag names and filenames.

  • Missinginclude. This exception is used when ColdFusion tries to call a file by using <cfinclude>, <cfmodule>, and <cferror> tags. Missinginclude exceptions are caught at runtime. They come under the subcategory of the Template exception type.

  • Expression. This exception occurs when an expression evaluation results in an error, such as if you try to add two different data types.

  • Lock. This exception occurs when a locking operation fails, as in the case of a time-out.

  • Security. This exception is used with ColdFusion security, such as authentication failure.

  • Object. This exception is used with errors associated with external objects, such as COM/DCOM, Corba, or Java.

  • Searchengine. This exception is used with search engines when processing the <cfindex>, <cfcollection>, or <cfsearch> tags.

  • Application. This exception is used when <cfthrow> tag doesn't specify any other type of exception and handles all application-generated errors.

  • Any. This type of exception includes all the preceding exceptions.

Note

ColdFusion also supports some built-in exceptions. For example, the COM.Allaire,ColdFusion.HTTPFileNotFound exception is raised when you use a file that doesn't exist in your ColdFusion code. For a complete list of these built-in exceptions, refer to the ColdFusion MX documentation.

Note

At the root, all ColdFusion exceptions are Java exceptions. In addition to being basic, custom, or advanced, you can identify an exception as belonging to a specific Java exception class. For example, if you try to use an array function, such as ArrayIsEmpty, on an integer variable, ColdFusion generates an exception that belongs to the Expression exception and coldfusion.runtime. NonArrayException Java class.




Macromedia ColdFusion MX. Professional Projects
ColdFusion MX Professional Projects
ISBN: 1592000126
EAN: 2147483647
Year: 2002
Pages: 200

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net