[Perl5-syntax] Syntax/implementation for try/catch
Ash Berlin
ash_cpan at firemirror.com
Tue Jan 13 19:40:44 GMT 2009
On 13 Jan 2009, at 19:26, Ash Berlin wrote:
> So eval sucks. I want proper try catch semantics. Some thing like
> this:
>
> sub foo {
> my ($self) = @_;
> try {
> $self->some_call_that_dies;
> return (qw/return value from foo/);
> }
> catch (My::Error $e where { $_->code >= 400 } ) {
> print("got My::Error code " . $e->code . "\n");
> }
> catch (Str $e) {
> print("Got str error: $e\n");
> }
> catch ($e) {
> print("Got unknown error: $e\n");
> }
> # $@ will be undef/previous value here.
> }
>
Oh yeah, and my current thinking is that this gets turned into:
sub foo {
try(sub {
$self->some_call_that_dies;
return (qw/return value from foo/);
},
$state_obj, sub{
print("got My::Error code " . $e->code . "\n");
},
$state_obj2, sub {
print("Got str error: $e\n");
},
$state_obj3, sub {
print("Got unknown error: $e\n");
});
# $@ will be undef/previous value here.
}
I haven't work out exactly what i'll Devel::Declare it into, but thats
a relatively minor detail once i've got the return issue sorted.
More information about the Perl5-syntax
mailing list