Skip to content

Instantly share code, notes, and snippets.

@xenoterracide
Created May 11, 2012 06:16
Show Gist options
  • Select an option

  • Save xenoterracide/2657880 to your computer and use it in GitHub Desktop.

Select an option

Save xenoterracide/2657880 to your computer and use it in GitHub Desktop.
Exception::Base subclassing with attributes
use 5.014;
use warnings;
use Try::Tiny;
use Exception::Base (
'My::Exception' => {
has => [ qw( usermsg logmsg attr ) ],
string_attributes => [ qw( usermsg logmsg ) ],
},
);
try {
My::Exception->throw(
value => 1,
attr => 'bad',
logmsg => 'really obscure and technical',
usermsg => 'this message is useless'
);
}
catch {
warn $_;
say $_->usermsg;
say 'this is really bad' if $_->attr eq 'bad';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment