http://www.perlmonks.org?node_id=673075


in reply to Re: RFC: Lexical Fatal.pm for Perl 5.10
in thread RFC: Lexical Fatal.pm for Perl 5.10

maybe use lethal; makes more sense.

I love the suggestion. Thank-you! Project named internally to 'lethal'. ;)

It would be nice if the lexical module took care of installing and backing out the exception handler.

While I appreciate the desire here, I'd argue that lethal is the wrong place to do it. I expect most Perl developers are used to seeing exception handling occur at the bottom of code. In traditional Perl 5:

eval { scrub($decks); weigh($anchor); sail_to($destination); }; if ($@) { warn "Uh oh, we had a problem with $@"; }

Or when using the Error module:

use Error; try { scrub($decks); weigh($anchor); sail_to($destination); } catch Error::Anchor with { my $E = shift; warn "The anchor's stuck due to $E"; } otherwise { my $E = shift; warn "We're not sailing due to $E"; };

In both cases (and in most languages), the exceptions are handled at the end, or in the calling code. I'd certainly be surprised to see the exception handler before the code that may throw the exception.

However I will be mindful to ensure that lethal inherits cleanly, so this can be implemented easily in a child module if you think it's a good idea. ;)

Many thanks for the excellent ideas,