Section 11.7 Stack Unwinding and Obtaining Information from an Exception Object
• When an exception is thrown but not caught in a particular scope, the method-call stack is un wound, and an attempt is made to catch
the exception in the next outer try
statement.
• Class Throwable
offers a printStackTrace
method that prints the method-call stack. Often, this is helpful in testing and debugging.
• Class Throwable
also provides a getStackTrace
method that obtains the same stack-trace information that’s printed by printStackTrace
(p. 461).
• Class Throwable
’s getMessage
method (p. 461) returns the descriptive string stored in an exception.
• Method getStackTrace
(p. 461) obtains the stack-trace information as an array of StackTrace Element
objects. ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.