How do stack traces get generated?

后端 未结 4 1933
盖世英雄少女心
盖世英雄少女心 2021-01-20 23:53

No single method in a program \"knows\" where it is on the stack. All it knows is its own little job, and it does that and returns. So when an Exception is thrown and a stack

4条回答
  •  萌比男神i
    2021-01-21 00:34

    You can know the Thread a method belongs to by using Thread.currentThread. Using this thread, you can get the StackTrace, because there is a stack for every thread in the JVM. Also, the main program runs in the main thread.

提交回复
热议问题