Is there a canonical way to print a stack trace in perl 6?

In perl 5, I would use any of the Carp functions. In perl 6, the search did not help, and trace pragma will print all the stacks, not just the ones I want. I could only use the old to crack the exception, catch it and print:

try { X::AdHoc.new(payload => 'Stack').throw; CATCH { when X::AdHoc { .say; } } } 

Or, being a little lazier:

 { die; CATCH { default { .say } } } 

What is the right way to do this?

+8
debugging perl6
source share
1 answer

I really found the answer when writing this question and decided to post it here, as it did not appear in any of my previous queries. The Perl 6 Backtrace class will receive a stack trace and convert it to a string:

 say "Stack: " ~ Backtrace.new; 

(Use Backtrace.new.full to see some additional low-level stack frames that are usually hidden.)

+7
source share