Prev | Current Page 382 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Here are the same two functions using a conditional statement
compiler directive:
public function getStack() : String
{
var str : String = ???Exception stack available in debug mode only.???;
#if debug
var es = haxe.Stack.exceptionStack();
str = StringTools.rpad( ???StackTrace\n???, ???=???, 21 ) + ???\n???;
str += haxe.Stack.toString( es );
#end
return str;
}
public function getCallStack() : String
{
var str : String = ???Call stack available in debug mode only.???;
#if debug
var cs = haxe.Stack.callStack();
str = StringTools.rpad( ???CallStackTrace\n???, ???=???, 26 ) + ???\n???;
str += haxe.Stack.toString( cs );
#end
return str;
}
As you can see, if the - debug flag is not set, then a default string value will be returned from the
function call, instead.
Now, this is all well and good, but there is a slight issue, here. It could very well be some time between
when the exception is created and thrown and when it is caught. This means that, while the
197
Chapter 7: When Things Go Wrong
exceptionStack() will now prove its usefulness, the callStack() function suddenly becomes
pointless, as any function listings it does provide will include calls that exist after the exception was
thrown, not the list of functions executed on the run up to the exception objects instantiation.


Pages:
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394