Skip to content

Instantly share code, notes, and snippets.

@moritz
Created March 25, 2013 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/5240038 to your computer and use it in GitHub Desktop.
Save moritz/5240038 to your computer and use it in GitHub Desktop.
User-oriented stack traces
my role Described[$by] {
method description() { $by }
}
multi sub trait_mod:<is>(Routine:D $r, :$descr!) {
$r does Described[$descr];
}
sub save-state() is descr('saving program state') {
save-all();
}
sub save-all() {
save-config();
}
sub save-config() is descr('saving user config') {
my $f = open :w, '/no/such/path';
}
try save-state();
if $! {
say "Error: $!.message()";
for $!.backtrace.list {
if .code.^can('description') {
say " while ", $_.code.description()
}
}
}
Error: Unable to open filehandle from path '/no/such/path'
while saving user config
while saving program state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment