Error.pm
æå確ãããç¨ãã¡ãªã¿ã« Exception::Class ã 㨠pacakge ãããããæ示çã«å²ãå½ã¦ãå¿ è¦ã¯ç¡ãã
#!/usr/bin/perl package ThrowableProcess::Exception; use base qw(Error::Simple); package ThrowableProcess::FirstException; use base qw(ThrowableProcess::Exception); package ThrowableProcess::SecondException; use base qw(ThrowableProcess::Exception); package ThrowableProcess; use strict; use warnings; use Carp::Clan; use Error qw(:try); sub do_something { my ($class, $is_first, $is_second) = @_; $is_first = 0 unless (defined $is_first && $is_first); if ($is_first) { throw ThrowableProcess::FirstException 'first exception!!!'; } elsif ($is_second) { throw ThrowableProcess::SecondException 'second exception!!!'; } else { croak 'normal croaking'; } } package main; use Carp; use Error qw(:try); use Perl6::Say; my @cases = ( [ 1, 0 ], [ 0, 1 ], [ 0, 0 ], ); for my $case (@cases) { my ($is_first, $is_second) = @$case; try { ThrowableProcess->do_something($is_first, $is_second); } catch ThrowableProcess::FirstException with { my $e = shift; say $e->text; } catch ThrowableProcess::SecondException with { my $e = shift; say $e->text; } otherwise { my $e = shift; croak $e; } finally { say "finally"; }; }
throw ã¨ã catch ã¨ã㯠Klass->method 㨠method Klass ã¨åæ§ã§ãããããããããã§ã¤ã³ãã¦ã¾ãã®ã§ãéä¸ã§ ";" ã¨ãå ¥ãã¡ãé§ç®ã