I wanted to get an email with information about the error. Like when and where it happened.
We're using the Fusebox framework with our app.
What I did to solve this was that I created a an cferror.cfm template/component. In that template I created an object and called it oErrorDetails. Now, there are two ways that information is going to get passed into that object. One is if an error occurs and another is a using a try/catch.
The component is called Alerts.
When an error occurs I don't have to worry about because it will take care of itself by calling the cferror template(because that's the template specified to handle errors). But I can also use that component with my try/catch. For example:
- <cftry>
-
<cfset Variables.temp = Variables.oStaffMember.load(Variables.nAdTeacherID) />
-
<cfcatch type="API.LXD.Validation">
-
<cfset Variables.temp = Request.oClientError.setError("noStaffMember", "A Staff Member ID has not been loaded.") />
-
-
<cfinvoke component="cfc.utility.facade.Alert" method="send" returnvariable="success">
-
<cfinvokeargument name="oFusebox" value="#myfusebox#" />
-
<cfinvokeargument name="oClientError" value="#request.oClientError#" />
-
<cfinvokeargument name="oErrorDetail" value="#cfcatch#" />
-
</cfinvoke>
-
</cfcatch>
-
</cftry>
I passed the information contained in "cfcatch" to the component using cfinvokeargument.
It's great because the component emails me information about the error like:
#oErrorDetail.message# and I will get that information no matter if it's an error or just something I tested for using the try/catch.
I must point out that there are differences (obviously) between what information I can get when I use cferror vs try/catch. This is simply solved by testing if certain variables are defined.
- <cfif IsDefined("oErrorDetail.template")>
-
<tr>
-
<td class="label" nowrap="nowrap"><strong>Occurred in Template </strong></td>
-
<td>#oErrorDetail.template#</td>
-
</tr>
-
-
</cfif>
In the previous code, only if
template in the oErrorDetail object is defined then we will get an email with that info. Otherwise, it will ignore it. This is because only cferror has that property - cfcatch, doesn't.
It took me while to figure this out. But I finally got it.