Skip to content

Instantly share code, notes, and snippets.

@clairvy
Created January 27, 2010 08:40
Show Gist options
  • Select an option

  • Save clairvy/287658 to your computer and use it in GitHub Desktop.

Select an option

Save clairvy/287658 to your computer and use it in GitHub Desktop.
example
$ ./test.pl > test.out
package E::A;
use Any::Moose;
extends 'Error::Simple';
1;
package E::B;
use base qw(Error::Simple);
1;
package E::C;
@ISA = qw(Error::Simple);
1;
catch 1st E::A
catch 2nd E::B
otherwise E::C
#!/usr/bin/env perl
use strict;
use warnings;
# try/catch をimport
# ついでに Error::Simple も使える
use Error qw(:try);
# Error::Simple を継承したローカル例外
use E::A;
use E::B;
use E::C;
package main;
{
my @errs = (
record E::A("hoge"),
record E::B("fuga"),
record E::C("fuga"),
);
foreach my $err (@errs) {
try {
throw $err;
print("try\n");
}
catch E::A with {
my $e = shift;
print("catch 1st ", ref($e), "\n");
} catch E::B with {
my $e = shift;
print("catch 2nd ", ref($e), "\n");
} otherwise {
my $e = shift;
print("otherwise ", ref($e), "\n");
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment