Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

debugging

raku

In perl 5, I would use any of the Carp functions. In perl 6, searching was no help, and the trace pragma will print all stacks, not just the one I want. I could only use the old hack of throwing an exception, catching it, and printing it:

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

Or, being a little lazier:

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

What's the right way to do this?

like image 544
piojo Avatar asked Aug 15 '17 05:08

piojo


1 Answers

I actually found the answer while writing this question, and decided to post it here since it didn't show up in any of my previous searches. Perl 6's Backtrace class will get 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 which are normally hidden.)

like image 155
piojo Avatar answered Nov 16 '22 02:11

piojo