Server-wide Error Handling

As of Version 4.5, ColdFusion provides site administrators with a way to handle errors and exceptions at the server level. Via the ColdFusion Administrator, you can designate a template to handle requests for CFML templates that don’t exist on the server. You can also specify an additional template that is invoked when an error or exception occurs anywhere within your ColdFusion application.

Missing Template Handler

Within the Settings section of the ColdFusion Administrator, there is a place for you to specify a Missing Template Handler. This template is called if a requested ColdFusion template can’t be found on the server, allowing you to avoid the dreaded “404 Object Not Found” error that otherwise results. Note that the Missing Template Handler isn’t invoked for template types other than CFML. In other words, requests for missing HTML templates are handled by the web server, not ColdFusion. When setting the Missing Template Handler, you should provide the physical path (not the URL) to the template’s location on your ColdFusion server.

If the template you are calling attempts to call another template that doesn’t exist, like as a custom tag call, CFMODULE, or CFINCLUDE, ColdFusion generates a MissingInclude exception but doesn’t invoke the Missing Template Handler. This exception can be trapped by placing the following code in the Application.cfm template of your application:

<CFERROR TYPE="Exception" EXCEPTION="MissingInclude" TEMPLATE="MissingIncludeHandler.cfm"> ...

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.