Created
March 24, 2014 23:53
-
-
Save bennadel/9752010 to your computer and use it in GitHub Desktop.
Determining Which Function Called This Function (Using ColdFusion)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffunction name="StackTrace" access="public" returntype="void" output="false"> | |
<!--- Define local variables. ---> | |
<cfset var Trace = StructNew() /> | |
<cftry> | |
<!--- Throw custom error. ---> | |
<cfthrow | |
message="This is thrown to gain access to the strack trace." | |
type="StackTrace" | |
/> | |
<!--- Catch custom error so that page doesn't crap out. ---> | |
<cfcatch> | |
<!--- | |
Create the trace object. The automatically | |
generated CFCATCH object (from CFTry/CFCatch) | |
should now have key elements that we can get | |
our hands on. | |
---> | |
<cfset Trace.StackTrace = CFCATCH.StackTrace /> | |
<cfset Trace.TagContext = CFCATCH.TagContext /> | |
<!--- Add stack trace to request. ---> | |
<cfset ArrayAppend( | |
REQUEST.StackTraces, | |
Trace | |
) /> | |
</cfcatch> | |
</cftry> | |
<!--- Return out. ---> | |
<cfreturn /> | |
</cffunction> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffunction name="A"> | |
<!--- Get stack trace. ---> | |
<cfset StackTrace() /> | |
<!--- Return the return of B(). ---> | |
<cfreturn B() /> | |
</cffunction> | |
<cffunction name="B"> | |
<!--- Get stack trace. ---> | |
<cfset StackTrace() /> | |
<!--- Return the return of C(). ---> | |
<cfreturn C() /> | |
</cffunction> | |
<cffunction name="C"> | |
<!--- Get stack trace. ---> | |
<cfset StackTrace() /> | |
<cfreturn "C is the bomb!" /> | |
</cffunction> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Create the stack trace array. ---> | |
cfset REQUEST.StackTraces = ArrayNew( 1 ) /> | |
<!--- Call all the methods. ---> | |
#A()#<br /> | |
#B()#<br /> | |
#C()#<br /> | |
<!--- Output the stack traces. ---> | |
<h2> | |
Stack Traces | |
</h2> | |
<cfloop | |
index="intI" | |
from="1" | |
to="#ArrayLen( REQUEST.StackTraces )#" | |
step="1"> | |
<h4> | |
Trace #intI# | |
</h4> | |
<cfdump var="#REQUEST.StackTraces[ intI ]#" /> | |
</cfloop> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment