Piotr Roszatycki

NAME

Fatal::Exception - Succeed or throw exception

SYNOPSIS

  use Fatal::Exception 'Exception::System' => qw< open close >;
  open my $fh, "/nonexistent";   # throw Exception::System

  use Exception::Base 'Exception::My';
  sub juggle { ... }
  Fatal::Exception->import('Exception::My' => 'juggle');
  juggle;          # succeed or throw exception
  Fatal::Exception->unimport('juggle');
  juggle or die;   # restore original behavior

DESCRIPTION

Fatal::Exception provides a way to conveniently replace functions which normally return a false value when they fail with equivalents which raise exceptions if they are not successful. This is the same as Fatal module from Perl 5.8 and previous but it throws Exception::Base object on error.

IMPORTS

use Fatal::Exception Exception => function, function, ...

Replaces the original functions with wrappers which provide do-or-throw equivalents. You may wrap both user-defined functions and overridable CORE operators (except exec, system which cannot be expressed via prototypes) in this way.

If wrapped function occurs fatal error, the error is converted into Exception::Fatal exception.

If the symbol :void appears in the import list, then functions named later in that import list raise an exception only when these are called in void context.

You should not fatalize functions that are called in list context, because this module tests whether a function has failed by testing the boolean truth of its return value in scalar context.

If the exception class is not exist, its module is loaded with "use Exception" automatically.

no Fatal::Exception function, function, ...

Restores original functions for user-defined functions or replaces the functions with do-without-die wrappers for CORE operators.

In fact, the CORE operators cannot be restored, so the non-fatalized alternative is provided instead.

The functions can be wrapped and unwrapped all the time.

PERFORMANCE

The Fatal::Exception module was benchmarked with other implementations. The results are following:

  ---------------------------------------------------------------
  | Module                      | Success       | Failure       |
  ---------------------------------------------------------------
  | eval/die                    |      289616/s |      236308/s |
  ---------------------------------------------------------------
  | Fatal                       |       94627/s |        8967/s |
  ---------------------------------------------------------------
  | Fatal::Exception            |      143479/s |        9677/s |
  ---------------------------------------------------------------

SEE ALSO

This module is a fork of Fatal module from Perl 5.8. The latest Perl will replace the Fatal module with autodie module which is similar to Fatal::Exception.

The Fatal::Exception doesn't work with lexical scope, yet. It also doesn't support "system" in perlfunc or "exec" in perlfunc core functions and extra import tags. It throws Exception::Base-d exceptions on failure so they can be handled as other Exception::Base-d exceptions.

More details:

Fatal, autodie, Exception::Base, Exception::System

BUGS

If you find the bug, please report it.

AUTHOR

Piotr Roszatycki <dexter@debian.org>

LICENSE

Copyright (C) 2007, 2008 by Piotr Roszatycki <dexter@debian.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html




Hosting generously
sponsored by Bytemark