Java, JavaScript and ABAP get the call stack Callstack of the current code through the code

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() + "-----");

}

test:

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();

test:

ABAP


CALL FUNCTION 'SYSTEM_CALLSTACK'

      IMPORTING

         callstack = lt_callstack.

test:

To get more Jerry's original technical articles, please follow the public account "Wang Zixi" or scan the QR code below:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324692900&siteId=291194637