ColdFusion 9.0 Resources |
Understanding errorsContents [Hide]You can look at errors in many ways; for example, you can look at errors by their causes. You can also look at them by their effects, particularly by whether your application can recover from them. You can also look at them the way ColdFusion does, as follows: About error causes and recoveryErrors can have many causes. Depending on the cause, the error can be recoverable. A recoverable error is one for which your application can identify the error cause and take action on the problem. Some errors, such as time-out errors, are recoverable without indicating to the user that an error was encountered. An error for which a requested application page does not exist is not recoverable, and the application can only display an error message. Errors such as validation errors, for which the application cannot continue processing the request, but can provide an error-specific response, can also be considered recoverable. For example, an error that occurs when a user enters text where a number is required can be considered recoverable, because the application can recognize the error and redisplay the data field with a message providing information about the cause of the error and telling the user to reenter the data. Some types of errors are recoverable in some, but not all circumstances. For example, your application can retry a request following a time-out error, but it must also be prepared for the case where the request always times out. Error causes fall in the broad categories listed in the following table:
Although these categories do not map completely to the way ColdFusion categorizes errors they provide a useful way of thinking about errors and can help you in preventing and handling errors in your code. ColdFusion error typesBefore you can effectively manage ColdFusion errors, you must understand how ColdFusion classifies and handles them. ColdFusion categorizes errors as detailed in the following table:
Note: The onSubmit and onBlur form field validation
techniques use JavaScript or Flash validation on the client browser.
About ColdFusion exceptionsMost ColdFusion errors are exceptions. You can categorize ColdFusion exceptions in two ways:
When exceptions occurColdFusion errors can occur at two times, when the CFML is compiled into Java and when the resulting Java executes, called runtime exceptions. Compiler exceptionsCompiler exceptions are programming errors that ColdFusion identifies when it compiles CFML into Java. Because compiler exceptions occur before the ColdFusion page is converted to executable code, you cannot handle them on the page that causes them. However, other pages can handle these errors. For more information, see Handling compiler exceptions. Runtime exceptionA runtime exception occurs when the compiled ColdFusion Java code runs. It is an event that disrupts the normal flow of instructions in the application. Exceptions can result from system errors or program logic errors. Runtime exceptions include:
ColdFusion exception typesColdFusion exceptions have types that you specify in the cferror, cfcatch, and cfthrow error-handling tags. A cferror or cfcatch tag handles only exceptions of the specified type. You identify an exception type by using an identifier from one (or more) of the following type categories:
Note: Use only custom error type names and the Application basic
type name in cfthrow tags. All other built-in exception
type names identify specific types of system-identified errors,
so do not use them for errors that you identify yourself.
Basic exception typesAll ColdFusion exceptions except for custom exceptions belong to a basic type category. These types consist of a broadly defined categorization of ColdFusion exceptions. The following table describes the basic exception types:
Note: The Any type includes all error with the Java
object type of java.lang.Exception. It does not include java.lang.Throwable
errors. To catch Throwable errors, specify java.lang.Throwable in
the cfcatch tag type attribute.
Custom exceptionsYou can generate an exception with your own type by specifying a custom exception type name, for example MyCustomErrorType, in a cfthrow tag. You then specify the custom type name in a cfcatch or cferror tag to handle the exception. Custom type names must be different from any built-in type names, including basic types and Java exception classes. Advanced exception typesThe Advanced exceptions consist of a set of specific, narrow exception types. These types are supported in ColdFusion for backward-compatibility. Java exception classesEvery ColdFusion exception belongs to, and is identified by, a specific Java exception class in addition to its basic, custom, or advanced type. The first line of the stack trace in the standard error output for an exception identifies the Java class of the exception. For example, if you attempt to use an array function such as ArrayIsEmpty on an integer variable, ColdFusion generates an exception that belongs to the Expression exception basic type and the coldfusion.runtime.NonArrayException Java class. In general, most applications do not use Java exception classes to identify exceptions. However, you can use Java class names to catch exceptions in non-CFML Java objects; for example, the following line catches all Java input/output exceptions: <cfcatch type="java.io.IOException"> How ColdFusion handles errorsThe following information describes briefly how ColdFusion handles errors. Detailed information is provided in the remaining topics. Missing template errorsIf a user requests a page that ColdFusion cannot find, and the Administrator Server Settings Missing Template Handler field specifies a Missing Template Handler page, ColdFusion uses that page to display error information. Otherwise, it displays a standard error message. Form field validation errorsWhen a user enters invalid data in an HTML tag that uses onServer or hidden form field server-side data validation ColdFusion does the following:
For more information on using hidden form field validation, see Validating Data. For more information on Application.cfc, see Designing and Optimizing a ColdFusion Application. Compiler exception errorsIf ColdFusion encounters a compiler exception, how it handles the exception depends on whether the error occurs on a requested page or on an included page:
Runtime exception errorsIf ColdFusion encounters a runtime exception, it does the action for the first matching condition in the following table:
For example, if an exception occurs in CFML code that is not in a cftry block, and Application.cfc does not have an onError method, but a cferror tag specifies a page to handle this error type, ColdFusion uses the specified error page. |