Try - nicer exception handling syntax
version 0.03
try { die "foo"; } catch { when (/foo/) { warn "Caught foo"; } }
This module implements a try/catch/finally statement. It is based heavily on (and mostly implemented via) Try::Tiny. The differences are:
It is a statement. my $foo = try { ... } doesn't work anymore, but in return, you don't have to remember the trailing semicolon anymore. eval still works fine if you need an expression (in 5.14+ at least).
my $foo = try { ... }
eval
The blocks are ordered, and only one catch and finally block are supported. try { } finally { } catch { } and try { } catch { } finally { } finally { } do not work with this module, mostly because that's just extra complexity for no real purpose.
try { } finally { } catch { }
try { } catch { } finally { } finally { }
catch and finally are no longer exported - they are just part of the syntax of the try statement. This is almost certainly not an issue.
catch
finally
try
try takes a block to run, and catch exceptions from. The block can optionally be followed by catch and another block and finally and another block. The catch block is run when the try block throws an exception, and the exception thrown will be in both $_ and @_. The finally block will be run after the try and catch blocks regardless of what happens, even if the catch block rethrows the exception. The exception thrown will be in @_ but not $_ (this may change in the future, since I'm pretty sure the reasoning for this is no longer useful in 5.14).
$_
@_
No known bugs.
Please report any bugs through RT: email bug-try at rt.cpan.org, or browse to http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Try.
bug-try at rt.cpan.org
Try::Tiny, TryCatch
You can find this documentation for this module with the perldoc command.
perldoc Try
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Try
CPAN Ratings
http://cpanratings.perl.org/d/Try
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Try
Search CPAN
http://search.cpan.org/dist/Try
Jesse Luehrs <doy at cpan dot org>
This software is Copyright (c) 2013 by Jesse Luehrs.
This is free software, licensed under:
The MIT (X11) License
To install Try, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Try
CPAN shell
perl -MCPAN -e shell install Try
For more information on module installation, please visit the detailed CPAN module installation guide.