-
-
Save clairvy/287658 to your computer and use it in GitHub Desktop.
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
| example | |
| $ ./test.pl > test.out |
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
| package E::A; | |
| use Any::Moose; | |
| extends 'Error::Simple'; | |
| 1; |
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
| package E::B; | |
| use base qw(Error::Simple); | |
| 1; |
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
| package E::C; | |
| @ISA = qw(Error::Simple); | |
| 1; |
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
| catch 1st E::A | |
| catch 2nd E::B | |
| otherwise E::C |
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
| #!/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