Seeing through Dave Rolsky's Exception::Class and
Sig::PackageScoped has let me make the following module, called
Exception::Handler.

In fact I rarely use $SIG{__DIE__} for exception handling, but the
concept of the module would be a bit interesting. Especially

  eval { };
  if ($@->isa('FooException')) {
      # ...
  } elsif ($@->isa('BarException')) {
      # ...
  } else {
      # ...
  }

code like this can be greatly simplified.

Any suggestions welcome, escpecially from gurus of exception, Matt
and Dave ;)  See t/*.t for typical usage.

http://bulknews.net/lib/archives/Exception-Handler-0.01.tar.gz

NAME
    Exception::Handler - Hierarchical exception handling

SYNOPSIS
      use Exception::Class
          'MyException',
          'AnotherException' => { isa => 'MyException' },
          'YetAnotherException' => { isa => 'AnotherException' },
          'FooBarException';

      use Exception::Handler
          MyException => \&my_handler,
          AnotherException => \&another_handler,
          __DEFAULT__ => \&default_handler;

      eval { MyException->throw };          # my_handler()
      eval { AnotherException->throw; };    # another_handler()
      eval { YetAnotherException->throw; }; # another_handler() : hierarchical
      eval { FooBarException->throw; };     # default_handler()

      sub my_handler {
          my $exception = shift;
          # ...
      }

      sub another_handler { }
      sub default_handler { }

DESCRIPTION
    Exception::Handler allows you to handle exception with various subs each
    of which registered for an appropriate class of exception. This module
    can nicely work with Dave Rolsky's Exception::Class and Grahamm Barr's
    Error module.

TODO
    *   Lexical handler, which may be done via "local".

AUTHOR
        Tatsuhiko Miyagawa <[EMAIL PROTECTED]>

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

SEE ALSO
        Exception::Class, Sig::PackageScoped



--
Tatsuhiko Miyagawa <[EMAIL PROTECTED]>

Reply via email to