in reply to Re: Try::Tiny - return in catch from sub
in thread Try::Tiny - return in catch from sub
if you want to return from your sub from within a try/catch then use as directedtry { die_sometimes(); } catch { # ...code run in case of error } finally { if (@_) { print "The try block died with: @_\n"; } else { print "The try block ran without error.\n"; } };
Try::Tiny is for when TryCatch is too much, it is not a drop in replacement, mind the caveatsuse TryCatch; sub foo { my ($self) = @_; try { die Some::Class->new(code => 404 ) if $self->not_found; return "return value from foo"; } catch (Some::Class $e where { $_->code > 100 } ) { } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Try::Tiny - return in catch from sub
by mjscott2702 (Pilgrim) on Nov 26, 2010 at 15:34 UTC | |
by Anonymous Monk on Nov 27, 2010 at 10:35 UTC |