• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Why would the variable "Error" be undefined in my error handling document?

New Here ,
Jan 19, 2016 Jan 19, 2016

Copy link to clipboard

Copied

I'm encountering an issue where I get, what appear to be, frequent exception errors.  Each says "Variable 'Error' is undefined" in line 73 of my application.cfm -- which is the same line that I'm calling for `<cfdump var="#error#" label="Error">`.

That cfdump is being sent to me via email so I can address errors, but the error message really doesn't reveal anything helpful, because it appears that the coldfusion variable "error" (a built-in variable) isn't being established.

I'm using application.cfc and error.cfm as my two main files to handle errors and can attach the code, but wanted to know if someone had a possible solution that was obvious based on what I've shared.

Thanks for your help.

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 19, 2016 Jan 19, 2016

Copy link to clipboard

Copied

steckinsights wrote:

.. because it appears that the coldfusion variable "error" (a built-in variable) isn't being established.

I've been working with ColdFusion since 2000, and I've never heard of there being a built-in variable called "error".  That's not to say it isn't so - just that I've never run across it in over 15 years of coding CF.

If the message is that "error" doesn't exist, then it does not exist.  It must be created SOMEwhere before it can be used.

But the only way we can help you to understand what is going on is to view the code that is causing the issue.  Can you post some of the code (in highlight, please) for us to review?  One of us might see something that you are skipping over.

The syntax highlight is only available in the advanced editor.

V/r,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2016 Feb 25, 2016

Copy link to clipboard

Copied

Thanks WolfShade.  I didn't realize that "error" wasn't a pre-defined variable in coldfusion.  Based on Raymond Camden's tutorial and the CFerror Docs‌, I thought it was.  But maybe that's only available within a particular template.  Steve Sommer's suggestions are helping me get to the right place for now, so I'll hold off on posting code.  Thanks for taking the time to review and help out!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 19, 2016 Jan 19, 2016

Copy link to clipboard

Copied

I think the error scope only exists in the template module of the cferror tag -- and I'm not 100% sure it still exists as I don't use it anymore. Instead I define an onError function in my application.cfc and use the exception parameter:

<cffunction name="onError" returntype="void" output="true" access="public" hint="I am executed when an unhandled error occurs">

  <cfargument name="exception" type="any" required="true" />

  <cfargument name="eventName" type="string" required="true" />

  <cfset local.template = "/error.cfm" />

  <cfset request.exception = arguments.exception />

  <cftry>

   <cfoutput><cfinclude template="#local.template#" /></cfoutput>

   <cfcatch type="any">

    <cfoutput>

     <h1>ARGH!</h1>

     <p>Something is really screwed up!</p>

     <cfdump var="#cfcatch#" label="Secondary Error" />

     <cfdump var="#request.exception#" label="Primary Error" />

    </cfoutput>

   </cfcatch>

  </cftry>

</cffunction>

In the above example I use "request.exception" where you would use "error".

Also note that I always put a try/catch block around my exception handler as CF does not react well to exceptions thrown within exception handlers. If this happens without the trap usually the most you will see is a Server 500 error with no hint of what failed.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2016 Feb 25, 2016

Copy link to clipboard

Copied

LATEST

Steve, Thanks for your help! Some of your comments/notes in the reply are helping me understand where I might be off -- I think I was relying on "error" that was set up in a template.  For now, I've defined "Error" using your tip example: <cfset request.exception = arguments.exception />

Seems to be working for me.  I'm going to test more and will mark as correct answer if I don't find any more issues.  Thanks so much!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation