Created
May 11, 2012 06:16
-
-
Save xenoterracide/2657880 to your computer and use it in GitHub Desktop.
Exception::Base subclassing with attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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