分享

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

 汪子熙 2019-03-03

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的原创技术文章,请关注公众号"汪子熙"

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多