Friday, September 20, 2024

Where You Put Your CFERROR Tag Matters

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 Murdok:

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.

Related Articles

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

Content management software. Video marketing statistics.