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:
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).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.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.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.
You can find this documentation for this module with the perldoc command.
perldoc Try
You can also look for information at:
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