Skip to content

Instantly share code, notes, and snippets.

@preaction
Created December 7, 2011 04:21
Show Gist options
  • Select an option

  • Save preaction/1441446 to your computer and use it in GitHub Desktop.

Select an option

Save preaction/1441446 to your computer and use it in GitHub Desktop.
Exception handling in Perl
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