Want to know what method you are currently executing, programmatically?
Posted by
Luis Majano
Aug 14, 2008 00:00:00 UTC
I am recently building a simple mock factory for cf7 (unfortunately I can't use coldmock, no cf8 goodness). One hurdle I was missing, is how to know which method I am currently executing in order to make a return look. Well, or good old friend java to the rescue. This is totally undocumented and please tread with care:
stack = CreateObject("java","java.lang.Exception").init().getStackTrace();
//loop over our stacktrace
for(x=1;x lte ArrayLen(stack);x=x+1){
if( findnocase( getMetdata(this).path, stack[x] ) ){
foundLine = stack[x];
break;
}
}
//cleanup our line
runningFunction = replacenocase(listlast(foundline.getClassName(),"$","func",""));
There you go!! That parses out the inner class name (your method) out of the compiled cf class that coldfusion created for you. I can now do my lookup against it.
Tags: ColdFusion
Josh Highland
when in doubt, parse it out
Ben Nadel
@Luis, that's pretty cool. Do you know if debugging has to be turned on in the Administrator in order for this to work?
Luis Majano
I think mine was off Ben, but I believe it bypasses whether you are in debug mode or not. Because you are getting an exception object, like if you where going to throw an exception.
Ben Nadel
Very cool. Thanks.