class Backtrace

Snapshot of the dynamic call stack

class Backtrace {}

A backtrace shows the dynamic call stack, usually leading up to a point where an exception was thrown.

It 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.

Methods

method new

Defined as:

multi method new(--> Backtrace:D)

Creates a new backtrace, using its calling location as the origin of the backtrace.

my $backtrace = Backtrace.new;

method gist

Defined as:

multi method gist(Backtrace:D: --> Str:D)

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:D:)

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 = Backtrace.new;
say $backtrace.Str;

method full

Defined as:

multi method full(Backtrace:D:)

Returns a full string representation of the backtrace, including hidden frames, compiler-specific frames and those from the setting.

my $backtrace = Backtrace.new;
say $backtrace.full;

method list

Defined as:

multi method list(Backtrace:D:)

Returns a list of Backtrace::Frame objects for this backtrace.

method summary

Defined as:

method summary(Backtrace:D: --> Str:D)

Returns a summary string representation of the backtrace, filtered by !.is-hidden && (.is-routine || !.is-setting).

This program:

sub inner { say Backtrace.new.summary }
sub outer { inner}
outer;

results in:

in method new at SETTING::src/core/Backtrace.pm6 line 85
in sub inner at test.p6 line 1
in sub outer at test.p6 line 2
in block <unit> at test.p6 line 3

method concise

Defined as:

method concise(Backtrace:D:)

Returns a concise string representation of the backtrace, filtered by !.is-hidden && .is-routine && !.is-setting.

This program:

sub inner { say Backtrace.new.concise }
sub outer { inner}
outer;

results in:

in sub inner at test.p6 line 1
in sub outer at test.p6 line 2

method map

Defined as:

multi method map(Backtrace:D: &block --> Seq:D)

It invokes &block for each element and gathers the return values in a sequence and returns it.

This program:

sub inner { Backtrace.new.map({ say "{$_.file}{$_.line}" }); }
sub outer { inner}
outer;

results in:

SETTING::src/core/Backtrace.pm6: 85
SETTING::src/core/Backtrace.pm6: 85
test.p6: 1
test.p6: 2
test.p6: 3
test.p6: 1

method flat

Defined as:

multi method flat(Backtrace:D:)

Returns the backtrace same as list.

Type Graph

Type relations for Backtrace
perl6-type-graph Backtrace Backtrace Any Any Backtrace->Any Mu Mu Any->Mu

Expand above chart