What do you need to get the ExeptionBean to work?

65 views
Skip to first unread message

Nathan Stanford Sr

unread,
Oct 13, 2011, 2:14:26 PM10/13/11
to col...@googlegroups.com
Where do you put the setting?
    I put it an onException in the main.cfc
Do I put a view to the exception in there? 
Can I send a email from there?

Nathan Stanford Sr

unread,
Oct 13, 2011, 2:15:29 PM10/13/11
to col...@googlegroups.com
Is there a working example somewhere?  I did not notice any inside the sample code.

Nolan Dubeau

unread,
Oct 13, 2011, 2:24:36 PM10/13/11
to col...@googlegroups.com
Hi Nathan,

Below is my Main.cfc onException function.  This could be a bit overkill, but I use both Logbox and Aaron Greenlee's HOTH - http://aarongreenlee.com/share/hoth-coldfusion-errors-tracking-reporting/

to track and log the errors.  Both of which are setup to email me the errors.

In addition I use cfsavecontent to display a friendly error message to the user.

Kudos go to Aaron for the code below.  Hope this helps.

Nolan


<cffunction name="onException" returntype="any" output="true">
<cfargument name="event" required="true">
<cfscript>
var rc = event.getCollection();
var prc = event.getCollection(private=true);


//log to HOTH
local.HothTracker = (structKeyExists(application, 'HothTracker'))
? application.HothTracker
: new Hoth.HothTracker( new platform.common.config.HothConfig() );


try {
//Grab Exception From request collection, placed by ColdBox
local.ExceptionBean = Event.getValue("ExceptionBean");


//log to logbox
if( log.canFatal() ){
log.fatal('#cgi.http_host# - Main.onException, detail - #local.ExceptionBean.getDetail()#, message - #local.ExceptionBean.getMessage()#',local.ExceptionBean.getStacktrace());
}

} catch (any e) {
// Record that the exception bean was not found!
// This should also provide the context of the original error
// however, the error details will be different. This is important
// in the event ColdBox has an issue capturing the error. 
local.HothTracker.track(e);


return;
}


local.HothTracker.track(local.ExceptionBean);


savecontent variable="local.e" {
        include '../views/500.cfm';
   }
   writeOutput(local.e);
</cfscript>
</cffunction>
On 2011-10-13, at 2:15 PM, Nathan Stanford Sr wrote:

Is there a working example somewhere?  I did not notice any inside the sample code.

--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To post to this group, send email to col...@googlegroups.com
To unsubscribe from this group, send email to coldbox-u...@googlegroups.com
For more options, visit this group at http://groups-beta.google.com/group/coldbox
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org

Nathan Stanford Sr

unread,
Oct 13, 2011, 2:58:24 PM10/13/11
to col...@googlegroups.com
Thanks I will try this out in my main.cfc - that is where it should be correct.

Nathan Stanford Sr

unread,
Oct 13, 2011, 3:09:53 PM10/13/11
to col...@googlegroups.com
What all do you need just to download hoth? and setup code in main.cfc

br...@bradwood.com

unread,
Oct 13, 2011, 3:15:34 PM10/13/11
to col...@googlegroups.com
You've got several questions here.  What exactly are you wanting to happen when your site errors?

Minimally speaking, if you want to get an E-mail and let the user see a pretty error page, then check out the following settings:
The "CustomErrorTemplate" setting will replace the generic "Oops" bug report page with a .cfm file of your choosing apologizing to your user for the unforeseen issue your site just experienced.

If you are on an older version of ColdBox, there are the following settings to E-mail you when an error happens:

bugTracers =
 {
    enabled                       = true,
    bugEmails                    = "xxx@xxx",
    mailFrom                      = "xxx@xxx",
    customEmailBugReport    = ""
 };

That functionality has been deprecated lately in favor of LogBox.  Configure an Appender (such as an E-mail appender) that listens for error log messages and it will kick in when an error occurs to let you know.

Now, if you are wanting to get more funky than simply outputting a custom "oops" page and E-mailing yourself, you have two options. 

The first is the exception handler setting that you set up in your config file with the "ExceptionHandler" setting. This is a ColdBox handler/action that accepts a variable in the request collection called "ExceptionBean".  In addition to running whatever code you want, you can use setNextEvent() to highjack the request and send the user wherever you want.  If you don't do that, ColdBox will eventually output your CustomErrorTemplate (or the default bug report template if that isn't set).

The second option you have is to register an interceptor that listens to the "onException" interception point.  The framework will call this whenever an exception occurs and the interceptData struct will have a key called "exception" which is the cfcatch that was caught.  You can pretty much do whatever you want in this interceptor as well, including redirecting to an other event. 

You can also have an exceptionHandler setting configured along with an onException interceptor and they will both fire, starting with any interceptors, then the handler.

Thanks

~Brad

br...@bradwood.com

unread,
Oct 13, 2011, 4:43:21 PM10/13/11
to col...@googlegroups.com
> I will try this out in my main.cfc - that is where it should be correct.

That is where most people stick it, but you can put your exception handler anywhere you want.  i.e.

exceptionHandler = "randomPackage.randomHandler.randomAction"

~Brad

Nathan Stanford Sr

unread,
Nov 2, 2011, 2:51:11 PM11/2/11
to col...@googlegroups.com
Is this true?


missingTemplateHandler = "main.onMissingTemplate",

If a missing file exists it will call the main.onMissingTemplate

exceptionHandler = "main.onException",

If an exception occurs it will call the main.onException 

onInvalidEvent = "main.pageNotFound",

If a event is not found it will call the main.pageNotFound 


customErrorTemplate = "views/errors/generic_error.cfm",

If a error occurs the page that will be displayed will be     views/errors/generic_error.cfm



Nathan Stanford Sr

unread,
Nov 2, 2011, 4:13:36 PM11/2/11
to col...@googlegroups.com
I am using ColdBox 3.1

bugTracers = 
 { 
    enabled                       = true, 
    bugEmails                    = "xxx@xxx", 
    mailFrom                      = "xxx@xxx", 
    customEmailBugReport    = "" 
 }; 

My understanding is that bugTracers has been replaced by using LogBox is this correct?

br...@bradwood.com

unread,
Nov 2, 2011, 4:46:56 PM11/2/11
to col...@googlegroups.com

Yes, that looks correct.

~Brad
-------- Original Message --------
Subject: [coldbox:12479] Re: What do you need to get the ExeptionBean
to work?
From: Nathan Stanford Sr <nathan....@gmail.com>

br...@bradwood.com

unread,
Nov 2, 2011, 4:47:41 PM11/2/11
to col...@googlegroups.com
That is correct as well.  LogBox is more complicated to configure, but gives you about 3000% more flexibility.

~Brad
-------- Original Message --------
Subject: [coldbox:12480] Re: What do you need to get the ExeptionBean
to work?
From: Nathan Stanford Sr <nathan....@gmail.com>
Date: Wed, November 02, 2011 3:13 pm
To: col...@googlegroups.com

Nathan Stanford Sr

unread,
Nov 3, 2011, 12:04:55 PM11/3/11
to col...@googlegroups.com
1. When we get errors they are not always clear as to what it wrong....

Example:
MissingInclude
Message
Could not find the included template /awng/views/myaccount/personalinfo.cfm


Yet when I go further down into the ColdFusion Exceptions area I get these two errors the first being the error.  This still is not very clear as to what is wrong.

Exceptions

11:58:45.045 - Database Exception - in C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF\cfusion\CustomTags\com\adobe\coldfusion\base.cfc : line 364
	    Error Executing Database Query.
	    
11:58:45.045 - MissingInclude Exception - in D:\apache\htdocs\ColdBox\system\plugins\Renderer.cfc : line 271
	    Could not find the included template /awng/views/myaccount/personalinfo.cfm.

If I take a new folder and create a simple application.cfm and index.cfm and call the objects in the handler I get a clearer picture as to what might be wrong with the object or query.

How can I get ColdBox to give me that information using LogBox in an email and display a nice error to the customer?

Can someone give me a one or two page example... like the sample apps.  Create a new ColdBox App with the Advanced Template and change whatever is needed to be changed to setup ColdBox 3.1 error handling to work.  Then cause a simple bad select or bad insert query and any other exception they want to show.  I would be very grateful.  I have been working on this over and over again.

Thanks for anyone's help.



br...@bradwood.com

unread,
Nov 3, 2011, 1:59:30 PM11/3/11
to col...@googlegroups.com
> 11:58:45.045 - Database Exception - in C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF\cfusion\CustomTags\com\adobe\coldfusion\base.cfc : line 364
> Error Executing Database Query.

This error is quite possibly being try/caught somewhere and not re-thrown.  You'll need to figure out why if that is the case.
Obviously, ColdBox can only handle errors which it as allowed to catch.  If you need more information about the error and are unable to find the try/catch block which is hiding it, running SQL Profiler might help. (Assuming you are on MS SQL)  Also, the standard ColdFusion logs may provide a complete stack trace for the error.

> If I take a new folder and create a simple application.cfm and index.cfm and call the objects in the handler I get a clearer picture as to what might be wrong with the object or query.

I'm not sure if I'm following that-- Are you saying that the error IS thrown when you run the same code outside of ColdBox? 

> How can I get ColdBox to give me that information using LogBox in an email and display a nice error to the customer?

This is two questions.  The first, is how can I get information about the error with LogBox.  In short, you can't if ColdBox isn't catching the error.  Minimally, you need to configure the E-mail appender.  (see below)

Your second question was how to display a pretty page to the user.  That is the customErrorTemplate setting.  Point it to a .cfm file which will be cfincluded.  In production, mine is:
customErrorTemplate        = "views/assets/callCustomerService.cfm",  // Sorry, please call customer service
On dev, it is:
coldbox.customErrorTemplate = '/common/views/assets/BugReport.cfm'; // Normal debug output of error information

It is important to note that the custom error template will not be included if you do a setNextEvent() in your exception handler. Plus, if you implement a exception handler, it's up to you to log the error.  I have more/less the following in my exception handler:

<cfproperty name="logBox" inject="logBox" scope="variables" />

<cfset variables.logger = variables.logBox.getLogger(getSetting("AppName"))>
<cfset logger.error(exceptionBean.getMessage(),exceptionBean)>

It's also worth noting that a coldbox.customErrorTemplate should be a stand-alone .cfm file which doesn't use the framework.  If the framework is having troubles starting up, it may not be able to display a standard event which can put you in a nasty loop.

> Can someone give me a one or two page example...

Sorry, I've got to get back to work, but perhaps someone else can throw a working example together.

In lieu of a full example, here is a chunk of logbox config (untested) that should define an E-mail appender that only E-mails Error and Fatal messages, but logs everything but debug to a text file:

//LogBox DSL
 logBox = {
         // Define Appenders
         appenders = {
                 logFile =
                     {
                         class = "coldbox.system.logging.appenders.AsyncRollingFileAppender",
                         levelMax=3, // Info
                         properties =
                             {
                                 filepath = "D:\logs\",
                                 autoExpand = false,
                                 filename = "myLogFile",   
                                 fileMaxSize = 2000,
                                 fileMaxArchives = 20   
                             }
                     },
                 email = {
                         class="coldbox.system.logging.appenders.EmailAppender",
                         levelMin="FATAL",
                         levelMax="ERROR",
                         properties = {
                                 subject = "",
                                 from = "myemail",
                                 to = "myemail"
                         }
                 }
         },
         // Root Logger
         root = { levelMin = "FATAL", levelMax = "INFO", appenders="*" },
         "coldbox.system" = { levelMin = "OFF", levelMax = "OFF" }
 };

Couple that with the customer error template setting above and that should E-mail you about errors, but display a pretty message to the user.

Thanks!



~Brad


Nathan Stanford Sr

unread,
Nov 3, 2011, 2:18:17 PM11/3/11
to col...@googlegroups.com
Brad I appreciate the work you are doing to help me get  an example.  This is a new application and there are no try catches in this area.  I made sure since we all are wanting better errors.  So I am trying to get as much info as I can.  I am trying what you gave me.  I got the file working to display to the customer... just not sure I am getting enough information related tot he error.
Reply all
Reply to author
Forward
0 new messages