Java,JavaScript和ABAP通过代码取得当前代码的调用栈Callstack

Java


StackTraceElement stack[] = Thread.currentThread().getStackTrace();

System.out.println("Callstack test");

for(int i = 0; i < stack.length; i++){

       System.out.println("Jerry:" + stack[i].getClassName() + ":" + stack[i].getMethodName() + "-----");

}

测试:

JavaScript


function getCallStack() {

   var stack = "Callstack:", fn =arguments.callee;

   while ( (fn = fn.caller) ) {

         stack = stack + "\n" +fn.name;

   }

   return stack;

}

function test1() {

    console.log(getCallStack());

}

function test2() {

    test1();

}

function test3() {

    test2();

}

function test4() {

    test3();

}

test4();

测试:

ABAP


CALL FUNCTION 'SYSTEM_CALLSTACK'

      IMPORTING

         callstack = lt_callstack.

测试:

要获取更多Jerry的原创技术文章,请关注公众号"汪子熙"或者扫描下面二维码:

你可能感兴趣的:(Java,JavaScript和ABAP通过代码取得当前代码的调用栈Callstack)