Quantcast

Where You Put Your CFERROR Tag Matters

Get the WebProNews Newsletter:
[ Business]

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.

Where You Put Your CFERROR Tag Matters
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. WebProNews Writer
Top Rated White Papers and Resources
  • 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#

  • Join for Access to Our Exclusive Web Tools
  • Sidebar Top
  • Sidebar Middle
  • Sign Up For The Free Newsletter
  • Sidebar Bottom