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

Creating detailed error messages like the default error template

New Here ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

 I'm using application.cfc's onError method to email me any CF exceptions that occur. Using the exception struct provided I'm able to create a somewhat detailed email message, but seems I don't have access to the same info that would normally be displayed in a CF error template, for example I want to see the lines of code that errored, to get that I would need to do a fileread on the template which seems hack-ish. Any better way to get something more like the default error handler?

 

TOPICS
Advanced techniques , Monitoring , Reporting

Views

175

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
Community Expert ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Have you dumped the error scope, or whatever scope you're referring to in the method for individual things? It should have what you need, as keys within that strict. I'm writing from a phone so can't readily test this to know.


/Charlie (troubleshooter, carehart.org)

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 ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Yes the struct CF provides is very detailed, I can rebuild most information traversing it. The paths depend and change based on the type of exception. However it doesn't look like I can get the lines of code for context without reading that myself from the template. I was more just wondering if someone already did this, seems like email alerts would be a common need, but maybe that's just me, I live off of email.

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
Community Expert ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

Sure. Most folks who have error handling still send emails. Some use dbs, some more sophisticated processing.

 

As for for seeing the code context, it may be that you need "robust exception handling" enabled in the cf admin (debugging page). I don't recall how that affects that specific  aspect of the error scope details, if at all. Worth a check. Again, am not at computer. 


/Charlie (troubleshooter, carehart.org)

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
Community Expert ,
Jun 13, 2022 Jun 13, 2022

Copy link to clipboard

Copied

LATEST
 

...seems I don't have access to the same info that would normally be displayed in a CF error template, for example I want to see the lines of code that errored


By @snowfields

 

As far as I know, none of ColdFusion's error-handling methods will show you the actual code that errored. Neither cferror, nor onError, nor try-catch.

 

Instead, each error struct - respectively, cferror, arguments.exception, cfcatch - shows you the file-path and line number of the code that errored. It is then up to you to use that information to locate the vexing code.  

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