Error Catching with CFERROR and CFCATCH - PowerPoint PPT Presentation

About This Presentation
Title:

Error Catching with CFERROR and CFCATCH

Description:

Errors are reported incorrectly (do you remember the 'exact' error message, sir? ... The native error code associated with this exception. ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 14
Provided by: dougla102
Category:

less

Transcript and Presenter's Notes

Title: Error Catching with CFERROR and CFCATCH


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
  • TypeRequest
  • Outdated. Use a global 404 handler for this.
  • Can't run CF code.
  • TypeException
  • Can run ANY cf code!
  • TypeMonitor
  • Very similar to Exception, except not visible to
    the user.
  • TypeValidation
  • 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 - TYPEDatabase 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 - TYPEDatabase 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 - TYPEExpression only.
    Internal expression error number.
  • CFCATCH.MissingFileName - TYPEMissingInclude
    only. Name of the file that could not be
    included.
  • CFCATCH.LockName - TYPELock only. The name of
    the affected lock (set to anonymous if the lock
    was unnamed).
  • CFCATCH.LockOperation - TYPELock only. The
    operation that failed (set to Timeout, Create
    Mutex, or Unknown).
  • CFCATCH.ErrorCode - TYPECustom type only. A
    string error code.
  • CFCATCH.ExtendedInfo - TYPEAPPLICATION 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
    TypeMonitor
  • Use the context array variable!
  • Always use TypeAny 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_at_teratech.com
  • http//www.teratech.com
  • Source Code http//www.cfug-md.org/meetings.cfm
Write a Comment
User Comments (0)
About PowerShow.com