To understand why exception conditions, or critical errors, occur, you need to understand the different types of errors that you can encounter. Because error conditions can occur at various points in the parse/execution process, it's important to know the ways in which you can distinguish such errors and make provisions for their handling.
For the purposes of our discussion, you should understand the four main types of errors that you might encounter when developing/running ColdFusion MX applications:
Runtime errors occur after your ColdFusion Markup Language (CFML) code has been compiled and is executing through the ColdFusion engine. Runtime errors often result from the fact that your application is receiving an error from a third-party resource (such as a database driver or COM object, and so on) that it isn't sure how to handle.
Runtime errors can also be caused by internal server errors or other conditions that are beyond your control. Further, you can purposefully generate runtime errors with CFTHROW tags for the purposes of error handling.
To fix conditions that generate runtime errors, you can examine the templates that are generating the errors and look for specific code segments that consistently cause the error. Often, this process involves commenting out all code in a given page and then reinserting it line by line until you discover the piece of code (or third-party resource) that is causing your server to produce errors.
In the event of internal server errors, you'll often find yourself pouring over the contents of the stack traces generated by the server to determine where things went wrong. Common causes of internal server errors include server memory corruption, improper administrator settings, and insufficient server resources.
Compiler errors are errors that occur as the ColdFusion Server attempts to compile your raw CFML code into Java. If you've developed ColdFusion applications for any length of time, you're certain to have come across a compiler error. These errors can be caused by an invalid CFML tag or improper use of CFML code within the template itself.
As ColdFusion begins to parse your American Standard Code for Information Interchange (ASCII) CFML templates to turn them into Java code, it needs to make sure that there are no critical errors in the code itself. If compiler errors are being thrown, you must fix them in the development process. To do so, you'll need to examine the error message you are receiving to determine in which template the errors are occurring. You then can make sure that you've got the CFML code syntactically correct before proceeding.
Because of their nature, compiler errors cannot be trapped by try/catch routines; compiler errors occur before the try/catch routine can be executed.
Input errors (or data errors) occur as a result of data that an end user has sent to your application (through a form field or similar input method).
Typically, when you have form fields available for user input, you are validating that data in some way on the server. If, for example, you have a form field reserved for the age of a user, you might be checking on the server that the value entered into this field is an integer. If the data entered doesn't mesh with the "rules" that you've set up for the field, an error will occur.
Generally, input errors are errors that you expect (and want) to occur if certain criteria are not met. Because you know that there will be occasions in which these errors are thrown, you'll typically code some sort of error handling into your application for them. This error handling might be as simple as returning the user to the previous page, with a notice as to why the data he or she entered was incorrect, missing, or in the wrong format.
As mentioned, input errors are generally expected within the framework of any application that accepts user input. These types of errors will generally never cause server instability or poor performance.
Missing Template Errors
Missing template errors are slightly different from standard 404 errors that you receive from your web server. The only real difference between a missing template error and a web server 404 error is the fact that the missing template error is actually sent from ColdFusion. ColdFusion answers any request for a template with a .cfm extension, including requests for templates that don't exist.
Naturally, the best way to resolve these errors is by looking carefully at the error message to determine if the template is actually missing.
The most common causes of missing template errors on production systems are typographical errors in the name of the template being called or a bad path in a link. (A bad path is revealed when CF looks for a specific template in a directory where it doesn't exist.) Fortunately, missing template errors are usually easily corrected by carefully examining the error message being reported.
Still, there will be times in which you cannot anticipate that missing template errors might be thrown. Fortunately, there is a provision in the ColdFusion Administrator that enables you to set up a default "missing template handler" for your web application. This missing template handler is displayed in place of the default error message whenever ColdFusion encounters a request for a CFM template that doesn't appear to exist.
Figure 9.1 gives you a view of the missing template handler dialog box in the ColdFusion Administrator.
Figure 9.1. Missing template handler dialog box.