Stack-Walking APIs
Exceptions do happen, especially during development or the period of software stabilization. But in a big complex system, the chance of getting an exception is possible even in production, especially when several third-party systems are brought together and the need arises to analyze the stack trace programmatically in order to apply an automatic correction. In this section, we will discuss how it can be done.
Stack Analysis before Java 9
The traditional reading of the stack trace, using objects of the java.lang.Thread
and java.lang.Throwable
classes, was accomplished by capturing it from the standard output. For example, we can include this line in any section of the code:
Thread.currentThread().dumpStack();
The previous line will ...
Get Java: High-Performance Apps with Java 9 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.