class Backtrace
Snapshot of the dynamic call stack
A backtrace contains the dynamic call stack, usually leading up to a point where an exception was thrown, and is a List of Backtrace::Frame objects. Its default stringification excludes backtrace frames that are deemed unnecessary or confusing; for example routines like &die
are hidden by default. Being a list, you can also access individual elements.
sub zipi ;tryif ($!)
This will print the last frame in the list, pointing at the line where it's happened.
Methods
method new
Defined as:
multi method new()multi method new(Int )multi method new(Mu \ex)multi method new(Mu \ex, Int )multi method new(List )multi method new(List , Int )
Creates a new backtrace, using its calling location as the origin of the backtrace or the $offset
that is passed as a parameter. If an object or a list (that will already contain a backtrace in list form) is passed, they will be used instead of the current code.
my = Backtrace.new;
method gist
Defined as:
multi method gist(Backtrace:)
Returns string "Backtrace(42 frames)"
where the number indicates the number of frames available via list method.
method Str
Defined as:
multi method Str(Backtrace:)
Returns a concise string representation of the backtrace, omitting routines marked as is hidden-from-backtrace
, and at the discretion of the implementation, also some routines from the setting.
my = Backtrace.new;say .Str;
method next-interesting-index
Defined as:
method next-interesting-index(Backtrace: Int = 0, :, :, :)
Returns the index of the next interesting
frame, once hidden and other settings are taken into account. $named
will decide whether to printed only those with a name, $noproto
will hide proto
s, and $setting
will hide those are considered setting.
sub zipi ;try zipi;say $!.backtrace.next-interesting-index; # OUTPUT: «2»say $!.backtrace.next-interesting-index( :named ); # OUTPUT: «4»
method outer-caller-idx
Defined as:
method outer-caller-idx(Backtrace: Int )
Returns as a list the index of the frames that called the current one.
sub zipi ;try zipi;say $!.backtrace.outer-caller-idx( 4 ); # OUTPUT: «[6]»
method nice
Defined as:
method nice(Backtrace: :)
Returns the backtrace as a list of interesting frames. If :$oneline
is set, will stop after the first frame.
sub zipi ;try zipi;say $!.backtrace.nice( :oneline ) if $!;# OUTPUT: « in sub zipi at /tmp/... line 1»
method full
Defined as:
multi method full(Backtrace:)
Returns a full string representation of the backtrace, including hidden frames, compiler-specific frames, and those from the setting.
my = Backtrace.new;say .full;
method list
Defined as:
multi method list(Backtrace:)
Returns a list of Backtrace::Frame objects for this backtrace.
method summary
Defined as:
method summary(Backtrace: --> Str)
Returns a summary string representation of the backtrace, filtered by !.is-hidden && (.is-routine || !.is-setting)
.
This program:
sub innersub outerouter;
results in:
in method new at SETTING::src/core/Backtrace.pm6 line 85in sub inner at test.p6 line 1in sub outer at test.p6 line 2in block <unit> at test.p6 line 3
method concise
Defined as:
method concise(Backtrace:)
Returns a concise string representation of the backtrace, filtered by !.is-hidden && .is-routine && !.is-setting
.
This program:
sub innersub outerouter;
results in:
in sub inner at test.p6 line 1in sub outer at test.p6 line 2
method map
Defined as:
multi method map(Backtrace: --> Seq)
It invokes &block
for each element and gathers the return values in a sequence and returns it.
This program:
sub innersub outerouter;
results in:
SETTING::src/core/Backtrace.pm6: 85SETTING::src/core/Backtrace.pm6: 85test.p6: 1test.p6: 2test.p6: 3test.p6: 1
method flat
Defined as:
multi method flat(Backtrace:)
Returns the backtrace same as list.