Catching the method that threw an error
I like to think we have a pretty good way to handle errors in our code. When an error is thrown, we email a dump of the CGI an cfactch to all the developers. We also include the following at the top of the email for quick reference.
Referrer:#cgi.http_referer#
Here is the users current URL:#cgi.path_info#?#cgi.query_string#
Here is where the user came from:#cgi.remote_addr#
All of this info has been helpful. The one thing it didn't provide free and clear is the file with the error and the method and, if it is a cfc, that had the error.
This was easier than I thought it would be. To get the file name that had the error, use the variable cfcatch.TagContext[1].template
Getting the method was a bit of a pain because I am really bad with regular expressions. The variable cfcatch.TagContext[1].raw_trace will look something like this
"at cfmakeError2ecfc399653279$funcGETERROR.runFunction(C:\www\error\makeError.cfc:5)"
In that string you will find $func. This comes right before the method name that was called. After that in al caps will be the method followed by .runFunction. So the regex I came up with is this.
rereplace(cfcatch.TagContext[1].raw_trace,'([[:print:]]*func)|(\.runFun[[:print:]]+)','','all')
This will remove everything before and after the method name leaving you with GETTERROR.
Now I use a conditional to make sure a method was called and I'm all good.
Method Called: #rereplace(cfcatch.TagContext[1].raw_trace,'([[:print:]]*func)|(\.runFun[[:print:]]+)','','all')#
If there is any interest, I can always show more of how we catch errors.
Referrer:#cgi.http_referer#
Here is the users current URL:#cgi.path_info#?#cgi.query_string#
Here is where the user came from:#cgi.remote_addr#
All of this info has been helpful. The one thing it didn't provide free and clear is the file with the error and the method and, if it is a cfc, that had the error.
This was easier than I thought it would be. To get the file name that had the error, use the variable cfcatch.TagContext[1].template
Getting the method was a bit of a pain because I am really bad with regular expressions. The variable cfcatch.TagContext[1].raw_trace will look something like this
"at cfmakeError2ecfc399653279$funcGETERROR.runFunction(C:\www\error\makeError.cfc:5)"
In that string you will find $func. This comes right before the method name that was called. After that in al caps will be the method followed by .runFunction. So the regex I came up with is this.
rereplace(cfcatch.TagContext[1].raw_trace,'([[:print:]]*func)|(\.runFun[[:print:]]+)','','all')
This will remove everything before and after the method name leaving you with GETTERROR.
Now I use a conditional to make sure a method was called and I'm all good.
Method Called: #rereplace(cfcatch.TagContext[1].raw_trace,'([[:print:]]*func)|(\.runFun[[:print:]]+)','','all')#
If there is any interest, I can always show more of how we catch errors.




Loading....