Difference between callStack and exceptionStack

Hej,

I can’t really understand what is the difference between the callStack and the exceptionStack when an exception is thrown.
ExceptionStack seems to have more details, is it the right thing to look at when debugging please ?

I’ve seen the doc but its not clear for me :

callStack():Array<StackItem>

Return the call stack elements, or an empty array if not available.

exceptionStack(fullStack:Bool = false):Array<StackItem>

Return the exception stack : this is the stack elements between the place the last exception was thrown and the place it was caught, or an empty array if not available. Set fullStack parameter to true in order to return the full exception stack.

May not work if catch type was a derivative from haxe.Exception.

Call stack points to a place where callStack() is invoked.
Exception stack points to a place where the exception was thrown.

Thanks for your answer Aleksandr but I don’t understand that ‘Call stack points to a place where callStack() is invoked.’
Maybe you could give me a pratical example ?

function main() {
    level1();
}

function level1() {
    try {
        level2();
    } catch(e:Dynamic) {
        //This will contain entries: main, level1, level2, level3
        trace(CallStack.exceptionStack(true));
        //This will contain entries: main, level1
        trace(CallStack.callStack());
    }
}

function level2() {
    level3();
}

function level3() {
    throw "Terrible error";
}
2 Likes

Wow many thx Aleksandr, it’s clear now !
So for debugging, exceptionStack is the best, no doubt !