Java Reference
In-Depth Information
Lambda expressions and streams can bring new challenges to your typical debugging routine.
We explore these in this section.
8.4.1. Examining the stack trace
When your program has stopped (for example, because an exception was thrown), the first thing
you need to know is where it stopped and how it got there. This is where stack frames are useful.
Each time your program performs a method call, information about the call is generated,
including the location of the call in your program, the arguments of the call, and the local
variables of the method being called. This information is stored on a stack frame.
When your program fails, you get a stack trace , which is a summary of how your program got to
that failure, stack frame by stack frame. In other words, you get a list of valuable method calls up
to when the failure appeared. This helps you understand how the problem occurred.
Lambdas and stack traces
Unfortunately, due to the fact that lambda expressions don't have names, stack traces can be
slightly puzzling. Consider the following simple code made to fail on purpose:
import java.util.*;
public class Debugging{
public static void main(String[] args) {
List<Point> points = Arrays.asList(new Point(12, 2), null);
points.stream().map(p -> p.getX()).forEach(System.out::println);
}
}
Running it will produce a stack trace along the lines of this:
 
Search WWH ::




Custom Search