Working with StackWalker
In this section you will become more familiar with how to work with StackWalker
. We will explore the following topics in this section:
- Getting an instance of
StackWalker
- Stack walking options
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,
as the name suggests...