Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: RFC: Lexical Fatal.pm for Perl 5.10

by pjf (Curate)
on Mar 09, 2008 at 08:47 UTC ( #673075=note: print w/ replies, xml ) Need Help??


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,


Comment on Re^2: RFC: Lexical Fatal.pm for Perl 5.10
Select or Download Code
Re^3: RFC: Lexical Fatal.pm for Perl 5.10
by BrowserUk (Pope) on Mar 09, 2008 at 09:40 UTC
    In both cases (and in most languages), the exceptions are handled at the end, or in the calling code.

    Well, if you use the $SIG{__DIE__} = sub (...) approach, this has to be done up front. The two approachs, signal handler and block eval serve slightly different purposes, but can be mixed I think.

    Anyway, good luck with your module :)


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://673075]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-08-01 03:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls