package Try; use strict; use warnings; # ABSTRACT: nicer exception handling syntax use Devel::CallParser; use XSLoader; XSLoader::load( __PACKAGE__, exists $Try::{VERSION} ? ${ $Try::{VERSION} } : (), ); use Exporter 'import'; our @EXPORT = our @EXPORT_OK = ('try'); use Try::Tiny (); =head1 SYNOPSIS try { die "foo"; } catch { when (/foo/) { warn "Caught foo"; } } =head1 DESCRIPTION This module implements a try/catch/finally statement. It is based heavily on (and mostly implemented via) L. The differences are: =over 4 =item * It is a statement. C<< my $foo = try { ... } >> doesn't work anymore, but in return, you don't have to remember the trailing semicolon anymore. C still works fine if you need an expression (in 5.14+ at least). =item * The blocks are ordered, and only one catch and finally block are supported. C<< try { } finally { } catch { } >> and C<< try { } catch { } finally { } finally { } >> do not work with this module, mostly because that's just extra complexity for no real purpose. =item * C and C are no longer exported - they are just part of the syntax of the C statement. This is almost certainly not an issue. =back =cut =head1 EXPORTS =head2 try C takes a block to run, and catch exceptions from. The block can optionally be followed by C and another block and C and another block. The C block is run when the C block throws an exception, and the exception thrown will be in both C<$_> and C<@_>. The C block will be run after the C and C blocks regardless of what happens, even if the C block rethrows the exception. The exception thrown will be in C<@_> but B C<$_> (this may change in the future, since I'm pretty sure the reasoning for this is no longer useful in 5.14). =cut sub try { my ($try, $catch, $finally) = @_; &Try::Tiny::try( $try, ($catch ? (&Try::Tiny::catch($catch)) : ()), ($finally ? (&Try::Tiny::finally($finally)) : ()), ); } =head1 BUGS No known bugs. Please report any bugs through RT: email C, or browse to L. =head1 SEE ALSO L, L =head1 SUPPORT You can find this documentation for this module with the perldoc command. perldoc Try You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * RT: CPAN's request tracker L =item * Search CPAN L =back =cut 1;