1 / 13

Error Catching with CFERROR and CFCATCH

Error Catching with CFERROR and CFCATCH. Douglas Smith, Application Architect TeraTech, Inc. Tuesday, October 9, 2001. Welcome/Goals. This presentation is about catching and monitoring errors, not general error handling Quick Review of CFERROR and CFCATCH When to use CFERROR vs. CFCATCH

lovie
Download Presentation

Error Catching with CFERROR and CFCATCH

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Error Catching with CFERROR and CFCATCH Douglas Smith, Application Architect TeraTech, Inc. Tuesday, October 9, 2001

  2. Welcome/Goals • This presentation is about catching and monitoring errors, not general error handling • Quick Review of CFERROR and CFCATCH • When to use CFERROR vs. CFCATCH • Tips and Tricks using CFERROR and CFCATCH

  3. Why Catch Errors • Users don't report errors! • Users go away if there are errors! • Client's don't report errors! • Remote web site (no access to CF log) • Errors are reported incorrectly (do you remember the "exact" error message, sir?") • Don't know how many errors there really are! • Higher confidence in your web site. • Security - Hide errors message from potential hackers, so they can't see code or database info

  4. How to Catch Errors • Display on the screen • Emailing Your Errors to yourself • Logging Your Errors to a DB or Text file

  5. CFERROR • Type=Request • Outdated. Use a global 404 handler for this. • Can't run CF code. • Type=Exception • Can run ANY cf code! • Type=Monitor • Very similar to Exception, except not visible to the user. • Type=Validation • Used for form validation • We are mainly concerned with "Exception" type for this presentation

  6. CFERROR Variables • Error.Diagnostics - Detailed error diagnostics from ColdFusion Server. • Error.MailTo - Email address of administrator who should be notified (corresponds to the value set in the MAILTO attribute of CFERROR). • Error.DateTime - Date and time when the error occurred. • Error.Browser - Browser that was running when the error occurred. • Error.GeneratedContent - The failed request's generated content . • Error.RemoteAddress - IP address of the remote client. • Error.HTTPReferer – Page from which the client accessed the link to the page where the error occurred. • Error.Template - Page being executed when the error occurred. • Error.QueryString - URL query string of the client's request.

  7. CFCATCH • Type = Any (default) • Type = APPLICATION (default) • Type = Database • Type = Template • Type = Security • Type = Object • Type = MissingInclude • Type = Expression • Type = Lock • Type = Custom_type

  8. CFCATCH Example • Current example is intended to be used as an include. • Can be setup to be a custom tag or module

  9. CFCATCH Variables • CFCATCH.Type - Exception type • CFCATCH.Message - The exception's diagnostic message, if one was provided. If no diagnostic message is available, this is an empty string. • CFCATCH.Detail - A detailed message from the CFML interpreter. This message, which contains HTML formatting, can help determine which tag threw the exception. • CFCATCH.TagContext - The tag stack: the name and position of each tag in the tag stack, and the full path names of the files that contain the tags in the tag stack. See the note that follows this list for more information. • CFCATCH.NativeErrorCode - TYPE=Database only. The native error code associated with this exception. Database drivers typically provide error codes to assist diagnosis of failing database operations. If no error code was provided, the value of NativeErrorCode is -1. • CFCATCH.SQLSTATE - TYPE=Database only. The SQLState associated with this exception. Database drivers typically provide error codes to assist diagnosis of failing database operations. If no SQLState value was provided, the value of SQLSTATE is -1. • CFCATCH.ErrNumber - TYPE=Expression only. Internal expression error number. • CFCATCH.MissingFileName - TYPE=MissingInclude only. Name of the file that could not be included. • CFCATCH.LockName - TYPE=Lock only. The name of the affected lock (set to anonymous if the lock was unnamed). • CFCATCH.LockOperation - TYPE=Lock only. The operation that failed (set to Timeout, Create Mutex, or Unknown). • CFCATCH.ErrorCode - TYPE=Custom type only. A string error code. • CFCATCH.ExtendedInfo - TYPE=APPLICATION and custom only. A custom error message.

  10. Other Variables that can be used • CGI.REMOTE_ADDR • CGI.HTTP_Referer • CGI.SCRIPT_NAME • CGI.HTTP_USER_AGENT • CGI.SERVER_NAME • user id if you have a members only site • Other app variables that tell you stuff

  11. CFERROR Summary • Pros • Global for entire application • Setup in one location • Easy! • When to Use • When you don't feel like learning about CFTRY/CFCATCH • When you need a quick, global solution • Tips and Tricks • Treat like any other page on your CF web site, give them a complete menu, etc. • Can contain custom tags and includes (header, footers, etc.)

  12. CFCATCH Summary • Pros • Can handle different exception types differently! • Can totally hide or ignore errors, as needed. • When to Use • You don't want to set the user off on another direction. • You want to handle different errors differently • You want to throw (and catch) your own errors • Want to retry a locked database error • When using Fusebox • Tips and Tricks • Treat like an include or module • Can be used in conjunction with CFERROR Type=Monitor • Use the context array variable! • Always use Type=Any unless you have a reason not to • If specifying the error type, always use ANY as catch all afterwards

  13. Contact Info • Douglas Smith, Douglas@teratech.com • http://www.teratech.com • Source Code: http://www.cfug-md.org/meetings.cfm

More Related