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.
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 produce the following output:
Similarly, we can include this line in the code:
new Throwable().printStackTrace();
The output will then look like this:
This output can be captured, read, and analyzed programmatically, but requires quite a bit of custom...