Stack Traces
A Stack Trace is a dump of the active call stack frames at a given point in time. This trace shows you where the error originated from and the series of statements that caused a specific command to be executed. Java creates a Stack Trace any time the Java Virtual Machine detects an error condition that causes a program to terminate. You may have experienced this when your programs have terminated because of a null pointer exception, or an array out of bounds exception.
Understanding the Stack Trace is a very important part of debugging. The exception is the type of bug that exists in your code. The Stack Trace illustrates both the specific line that caused the exception, and the path your execution took to reach that conclusion.
In the example above, we can extract the following knowledge about the bug that caused our program to terminate:
- There is a statement that is passing a null value in place of an object, hence raising a Null Pointer Exception.
- The specific statement that caused the exception can be found in
Lab6.java
on line 15. - The bug occurred as a result of
Lab6.java
line 35.
Eclipse & Stack Traces
Eclipse generates clickable references in the console whenever a stack trace is generated. Clicking a link will automatically take you to the specific line in the stack trace.To see this in action, execute Lab6.java and click on the different links in the stack trace.