For what it is worth - I would encourage you to check out the Error package as well.
Rather than: eval { }; if ($@->isa('FooException')) { # ... } elsif ($@->isa('BarException')) { # ... } else { # ... } You would have: try { code; } catch FooException with { code for FooExceptions; } catch BarException with { code for BarExceptions; } otherwise { }; And you can throw exceptions with details on the nature of the exception: throw FooException ( -text => "You foo'ed at line bar", -value => $line ); and in the try block: try { do foo; } catch FooException with { my $exception=shift; print "Uh oh, we have a problem with foo: " . $exception->text; }; Jay ----- Original Message ----- From: "Tatsuhiko Miyagawa" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: "Dave Rolsky" <[EMAIL PROTECTED]>; "Matt Sergeant" <[EMAIL PROTECTED]> Sent: Friday, January 11, 2002 8:07 AM Subject: RFC: Exception::Handler > 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]> > >