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.

Stack Trace Image

In the example above, we can extract the following knowledge about the bug that caused our program to terminate:

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.