Tony,

I have a custom tag that I wrote to display exception information and it
catches some of the random error that happen when just cfdumping a cfcatch
variable.  Call it like: <cf_showexception exception="#cfcatch#"/>
I put it below.

Paul Kenney
[EMAIL PROTECTED]
916-212-4359

---START CODE---

<cffunction name="parseStackTrace" returntype="array" output="false">
<cfargument name="StackTrace" type="array" required="true"/>
<cfargument name="Mask" type="string" required="false"/>
<!---  --->
<cfset var aGroup = ArrayNew(1)>
<cfset var LineNumMask = "L" & RepeatString("0",
Len(toString(ArrayLen(Arguments.StackTrace))))>
<cfset var ElemMask = "[i] -- c.m( ) -- f:l">
<cfset var i = 0>
<cfset var j = 0>
<cfset var maskChar = "">
<cfset var Elem = StructNew()>
<cfset var ret = ArrayNew(1)>

<cfset Elem["Val"] = "">
<cfset Elem["Str"] = "">
<cfset Elem["Pos"] = "">
<cfset Elem["Class"] = "">
<cfset Elem["File"] = "">

<cfif StructKeyExists(Arguments, "Mask")>
<cfset ElemMask = Arguments.Mask>
</cfif>
<cfif NOT Len(ElemMask)>
<cfset ElemMask = "*">
</cfif>

<!--- Loop over the indexes of the "Arguments.StackTrace" array in reverse
order. --->
<cfloop index="j" from="#ArrayLen(Arguments.StackTrace)#" to="0" step="-1">
<cfif NOT j OR ListFind("runFunction,runPage,service",
Arguments.StackTrace[j].getMethodName(), ",")>
<cfset ArrayPrepend(ret, aGroup)>
<cfif NOT j>
<cfbreak/>
</cfif>
<cfset aGroup = ArrayNew(1)>
</cfif>

<cfset Elem.Val = Arguments.StackTrace[j]>
<cfset Elem.Str = "">

<!--- Loop over the characters in the "ElemMask". --->
<cfloop index="i" from="1" to="#Len(ElemMask)#">
<cfscript>
maskChar = Mid(ElemMask, i, 1);
switch(maskChar)
{
case "c": // Class name
Elem.Str = Elem.Str & Elem.Val.getClassName();
break;
case "f": // Filename
Elem.Str = Elem.Str & Elem.Val.getFileName();
break;
case "i": // Current Index into the StackTrace array.
Elem.Str = Elem.Str & NumberFormat(j, LineNumMask);
break;
case "l": // Line number in file.
Elem.Str = Elem.Str & Elem.Val.getLineNumber();
break;
case "m": // Method name
Elem.Str = Elem.Str & Elem.Val.getMethodName();
break;
case "*":
Elem.Str = Elem.Str & Elem.Val.toString();
break;
default:
Elem.Str = Elem.Str & maskChar;
}
</cfscript>
</cfloop>
<cfset ArrayPrepend(aGroup, Elem.Str)>
</cfloop>

<cfreturn ret/>
</cffunction>

<cfparam name="Attributes.Exception" type="any" default=""/>

<cfif IsDebugMode()>
<cfif NOT IsSimpleValue(Attributes.Exception)>
<cfset catch = Attributes.Exception>
<cfelseif StructKeyExists(Caller, "cfcatch")>
<cfset catch = Caller.cfcatch>
<cfelse>
<cfexit method="exittag"/>
</cfif>
<cfelse>
<cfexit method="exittag"/>
</cfif>

<cfset ThisTag.Info = StructNew()>
<cfset ThisTag.Stacks = StructNew()>

<cfloop collection="#catch#" item="key">
<cfset Dest = "Info">
<cfset Value = "">
<cftry>
<cfswitch _expression_="#key#">
<cfcase value="StackTrace">
<cfinclude template="#Request.UDF#/us/pjk/debug/parseStackTrace.cfm"/>
<cfset Value = parseStackTrace(catch.StackTrace)>
<cfset Dest = "Stacks">
</cfcase>
<cfcase value="TagContext">
<cfset Value = catch[key]>
<cfset Dest = "Stacks">
</cfcase>
<cfcase value="objectType">
<cfif IsObject(catch[key])>
<cfset Value = catch.objectType.getName()>
<cfelse>
<cfset Value = catch.objectType>
</cfif>
<cfset Dest = "Info">
</cfcase>
<cfdefaultcase>
<cfset Value = catch[key]>
<cfset Dest = "Info">
<cfif IsObject(Value)>
<cfset Value = Value.toString()>
</cfif>
<cfif IsSimpleValue(Value)>
<cfset Value = ReplaceList(Value, "&gt;,&lt;,&quot;", ">,<,""")>
</cfif>
</cfdefaultcase>
</cfswitch>

<cfset ThisTag[Dest][key] = Value>

<cfcatch type="any">
<!--- Do nothing here. --->
</cfcatch>
</cftry>
</cfloop>

<cfif StructKeyExists(ThisTag.Stacks, "TagContext") AND NOT
StructKeyExists(ThisTag.Info, "Template")>
<cfif IsArray(ThisTag.Stacks.TagContext) AND
ArrayLen(ThisTag.Stacks.TagContext)>
<cfset ThisTag.Info["Template"] = ThisTag.Stacks.TagContext[1].Template>
</cfif>
</cfif>

<cfif StructCount(ThisTag.Stacks)>
<cfset LeftWidth = "75%">
<cfset HeaderColSpan = "3">
<cfset ShowRight = TRUE>
<cfelse>
<cfset LeftWidth = "100%">
<cfset HeaderColSpan = "1">
<cfset ShowRight = TRUE>
</cfif>

<cfoutput>
<br><br>
<table border="1" cellpadding="5" cellspacing="0" width="100%"><tr><td>
<table width="100%" border="0" cellspacing="0" cellpadding="2"
style="background:0000cc;color:ffffff;">
<tr><td align="center"><span style="font: bold 14pt Arial, Helvetica,
sans-serif;">- EXCEPTION -</span></td></tr>
</table>
<br>
<table border="1" cellpadding="2" cellspacing="0" width="100%">
<tr><td>
<table>
<tr valign="top">
<td width="#LeftWidth#">
<cfdump var="#ThisTag.Info#" label="Exception Information"
expand="true"/>
</td>
<cfif ShowRight>
<td>&nbsp;</td>
<td><cfdump var="#ThisTag.Stacks#" label="Trace Information"
expand="false"/></td>
</cfif>
</tr>
</table>
</td></tr>
</table>
</td></tr></table>
</cfoutput>

<cfexit method="exittag"/>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to