Created
December 7, 2011 04:21
-
-
Save preaction/1441446 to your computer and use it in GitHub Desktop.
Exception handling in Perl
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 Exception::Class( "My::X::NoData" ); | |
| sub could_die { | |
| if ( rand > 0.5 ) { My::X::NoData->throw; } | |
| } | |
| sub will_die { | |
| []->{something}; | |
| } | |
| eval { | |
| could_die(); | |
| will_die(); | |
| }; | |
| if ( my $e = My::X::NoData->caught ) { | |
| print "Ha ha!"; | |
| } | |
| elsif ($@) { | |
| die $@; # die at this line, not in will_die() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment