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?
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With