Quantcast
750×100
Read WebProNews
With Friends!

Where You Put Your CFERROR Tag Matters

Get the WebProNews Newsletter:

Chalk this up to the “I can’t believe you never saw this before” file.

While this is incredibly obvious, I never really ran into this until today.

Where you put your CFERROR tag (for those using Application.cfm instead of Application.cfc) matters.

Consider:

<cferror template="exception.cfm" type="exception">
<cfoutput>#x#</cfoutput>

The code above will work correctly.

<cfoutput>#x#</cfoutput>
<cferror template="exception.cfm" type="exception">

The code above will not work correctly because the error occurs before ColdFusion has been told what to do with an error.

As I said – incredibly obvious but it never really bit me in the rear till today.

Now you might say – why not just move it to the top of your Application.cfm file. Well that would work – but what if your exception handler itself uses variables in the Application scope?

For example – an application.adminemail setting to know where to fire off error reports. I think you might consider doing code something like so in your exception handler:

<cfif not structKeyExists(application, "adminemail")>
  <cfset mailTo="some hard coded address">
<cfelsegt;
  <cfset mailTo = application.adminemail>
</cfif>

While it is never nice to hard code values – it might be acceptable as a last case resort. Someone remind me tomorrow and I’ll post my “typical” exception handler.

Comments

Tag:

Digg | Reddit | Furl

Bookmark WebProNews:

Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long
time ColdFusion user, Raymond has worked on numerous ColdFusion books
and is the creator of many of the most popular ColdFusion community web
sites. He is an Adobe Community Expert, user group manager, and the
proud father of three little bundles of joy.

About Raymond Camden
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.
Top Rated White Papers and Resources
There is 1 Comment. Add Yours.
  1. Like (0) Dislike (0)
    Anwar

    Can we user CFOUTPUT in the template which we have specified in the cferror tag.

    Because when I try to use it, I don’t see any effect of cfoutput.

    eg. #x#

    - it gives me the output as #x#

    Reply

What do you think? Respond.

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>