Getting an instance of StackWalker

To perform the walking over the stack elements we need an instance of the stack walker. To do that, we invoke the getInstance() method. As shown here, there are four overloaded versions of this method:

  • static StackWalker getInstance()
  • static StackWalker getInstance(StackWalker.Option option)
  • static StackWalker getInstance(Set<StackWalker.Option> options)
  • static StackWalker getInstance(Set<StackWalker.Option> options, int estimateDepth)

The first version does not take any arguments and returns a StackWalker instance that will let us walk through normal stack frames. This is usually what we would be interested in. The other versions of the method accept a StackWalker.Option value or values. The enum StackWalker.Option, ...

Get Java 9: Building Robust Modular Applications 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.