120 likes | 255 Views
Dynamic Debug Output and Error Handling in CF5 and CFMX. November 12, 2002 By Douglas M. Smith Application Architect for Teratech, Inc. Reasons for this Presentation.
E N D
Dynamic Debug Output and Error Handling in CF5 and CFMX November 12, 2002 By Douglas M. Smith Application Architect for Teratech, Inc.
Reasons for this Presentation • I wanted to see the web site exactly as the client would see it, yet at the same time, I wanted developer’s to see debug and error output. • I wanted to allow developers to view debug and error info, but hide it from regular users. • I wanted to embed custom debug output in my code during development, and keep it available for later testing and bug fixing, without having to comment code in and out. • I wanted a mechanism to turn dynamically turn on/off the standard CF debug output display (at the bottom of each page) • For security reasons, I only wanted the developer to be able to see or turn on error or debug output.
Code in Application.cfm • Sets variables that are used in <CFERROR> and <CFCATCH> error handling templates • Sets variables that are used to control access to debug output. Basically, these are lists of IP addresses, similar to how the CF Admin controls access to debug output. • Has code to set CLIENT.DEBUG variable, which is the main switch variable. • Sets the <CFERROR> template.
Code in OnRequestEnd.cfm • Code to turn on/off standard CF debug output • Code to turn on/off custom debug output • In CF5, use MOD_DISPLAY_VARIABLES.cfm • In CFMX, don’t need this. Can use settings in CFADMIN, or just use CFDUMP
Code in <CFERROR> Template Usage: <cferror type="exception" template="error_exception.cfm"> • Code to email any error to web master • Code to turn off email, and display error, if desired by developer • In CFMX, code to display error context
Custom Debug Output Code Put code like this this wherever you want custom debug output: <cfif Client.Debug> Your custom debug output. </cfif>
Code in <CFCATCH> Template Usage: <CFCATCH><CFINCLUDE template=“error_catch.cfm”> </cfcatch> • Very similar to CFERROR • Code to email any error to web master • Code to turn off email, and display error, if desired by developer • In CFMX, code to display error context
“Gotchas” • Code in Application.cfm before the <cferror> statement is not caught by anything, so make sure it is bug-free. • Error handlers must be tested and be error free before they will work. This is especially important in CFMX. • If there is an error in the error_handler, you won’t get your email. Generate an error using <cfabort showerror="x"> to make sure you are getting your error emails.
More “Gotchas” • Compilation errors in normal code are not caught by CFERROR handler. These are displayed to standard error output. Only runtime errors are caught. • Compilation errors in CFERROR handler itself under CFMX are not reported at all! It simply appears like the <CFERROR> tag does not work. You will get default debug output to the screen, and you will loose error handling benefits.
New Features in CFMX • <CFDUMP> is awesome! • TagContext is now available in <CFERROR> as well as in CFCATCH • Standard debug output has actual line numbers, and error in bold. Cool, but feature is lost when using error or cfcatch variables!
Contact Info Douglas M. Smith Douglas@teratech.com Download this presentation from: http://www.cfug-md.org/