22.08.2013 Views

ColdFusion Developer's Guide

ColdFusion Developer's Guide

ColdFusion Developer's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta<br />

Handling missing template errors<br />

Missing template errors occur when <strong>ColdFusion</strong> receives an HTTP request for a page ending<br />

in .cfm that it cannot find. You can create your own missing template error page to present<br />

application-specific information or provide an application-specific appearance. You specify<br />

the missing template error page on the Administrator Settings page.<br />

The missing error page can use CFML tags and variables. In particular, you can use the<br />

CGI.script_name variable in text such as the following to identify the requested page:<br />

The page #Replace(CGI.script_name, "/", "")# is not<br />

available.<br />

Make sure that you entered the page correctly.<br />

<br />

(In this code, the Replace function removes the leading slash sign from the script name to<br />

make the display more friendly.)<br />

Handling form field validation errors<br />

When you use server-side form field validation, the default validation error message describes<br />

the error cause plainly and clearly. However, you might want to give the error message a<br />

custom look or provide additional information such as service contact phone numbers and<br />

addresses. In this case, use the cferror tag with the Validation attribute in the<br />

Application.cfc initialization code or on the Application.cfm page to specify your own<br />

validation error handler. The section “Example of a validation error page” on page 376<br />

provides an example of such a page. You can also put form field validation error handling code<br />

in the Application.cfc onError method.<br />

Handling compiler exceptions<br />

You cannot handle compiler exceptions directly on the page where they occur, because the<br />

exception is caught before <strong>ColdFusion</strong> starts running the page code. You should fix all<br />

compiler exceptions as part of the development process. Use the reported error message and<br />

the code debugging techniques discussed in Chapter 19, “Debugging and Troubleshooting<br />

Applications” to identify and correct the cause of the error.<br />

Compiler exceptions that occur on pages you access by using the cfinclude or cfmodule tags<br />

can actually be handled as runtime errors by surrounding the cfinclude or cfmodule tag in a<br />

cftry block. The compiler exception on the accessed page gets caught as a runtime error on<br />

the base page. However, you should avoid this "solution" to the problem, as the correct<br />

method for handling compiler errors is to remove them before you deploy the application.<br />

Determining error-handling strategies 371

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!