A few additions:

You don't really need the conditional logic around the cferror tag. 

It might be wise to also include a "request" error handler e.g.

<cferror type="request"...>

Although you are restricted to the number of variables you can use in
this template (and you can't log/mail etc.) it provides a fallback in
case there happens to be an error in your exception handler defined by

<cferror type="exception"...>

And thus you avoid being "hosed".

If you want to replace try/catch for queries then the most appropriate
exception type to specify is "database" e.g.

<cferror type="exception" exception="database">

Naturally, the most logical place to put these tags is in
Application.cfm though, as with <cfapplication> etc., you are not
restricted to doing so i.e. you can override the exception handler on
any given page as necessary or appropriate.

You also need to be aware that if an error or exception occurs before
you have called <cferror> e.g. somewhere high up in Application.cfm then
your error handlers won't run.

This contribution is purely for my own benefit as I wanted something to
type.


André

-----Original Message-----
From: [EMAIL PROTECTED] [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
Sent: 04 March 2003 18:05
To: CF-Talk
Subject: site wide error handling

Instead of using the try/catch blocks around each query, use a site-wide
error catcher that you set up in the Application.cfm file:

<cfif (#CGI.SCRIPT_NAME# NEQ "/includes/errorhandler.cfm")>
        <cferror template="/includes/errorhandler.cfm"  type="exception"
exception="ANY">
</cfif>

The key is to use the type of "exception" and exception="any" (I think
this came in to either v4.51 or v5).

So if an error is caught, the users is tossed to the errorhandler.cfm
page, where you display a "Sorry, error occured" or whatever message and
you set the following params:

<cfparam name="error.template" default="unknown">
<cfparam name="error.querystring" default="unknown">
<cfparam name="error.remoteaddress" default="unknown">
<cfparam name="error.HTTPreferer" default/index.cfm">
<cfparam name="error.diagnostics" default="unknown">

You can use the error structure (error.[whatever]) to then send mail to
an admin and/or dump into a database (I do both).

Just make sure to CFPARAM everything that will be called, or you will
get an error in the error-handler page and you'll be hosed.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to