How do stack traces get generated?

后端 未结 4 1905
盖世英雄少女心
盖世英雄少女心 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条回答
  •  不知归路
    2021-01-21 00:37

    When you create a Throwable (not when you throw it) it records the stack trace is a low level/hidden way associated with the Throwable. When you call getStackTrace() the first time it creates the StackTraceElement[] objects from the low level information. It doesn't this lazily as the stack trace is often not used.

提交回复
热议问题