Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Use of "die" in OO modules

by adrianh (Chancellor)
on Jan 19, 2007 at 12:24 UTC ( #595439=note: print w/ replies, xml ) Need Help??


in reply to Use of "die" in OO modules

You can put me in the "use exceptions (plus Exception::Class if you need to return more than just 'an error happened'" camp.

My reasons for this still match the ones I wrote at Re^2: Best Practices for Exception Handling.


Comment on Re: Use of "die" in OO modules
Re^2: Use of "die" in OO modules
by theguvnor (Chaplain) on Jan 19, 2007 at 13:36 UTC

    Thanks for the link - interesting reading. The whole raison d'etre for my original post was that though I philosophically fall into the same camp, I have problems with the implementation/execution - in the absence of true built-in Exception handling, I have to decide between a couple of options: either fake up a try/catch type of thing by using eval {...}; if($@){...} or go with the old return undefined and let the caller inspect the object's error() method.

    [Jon]

      in the absence of true built-in Exception handling

      I'm curious, since I've heard others saying this, why you think Perl's exception handling isn't "true" or "built-in"?

        Well, I guess it's a matter of defining what we mean. My definition would be that when code does something exceptional i.e. contrary to the "normal" flow or producing an unwanted error condition, the interpreter will interrupt program flow by propagating an object that encapsulates the error information, up through the stack until it finds code ready to handle it. The key here is that while die within an eval{} sets $@, that is an error variable, but it is not really much of an object (at least, not in the sense that it's commonly used and understood by practitioners of Object-Oriented paradigm). I'm aware that there are CPAN modules that implement Exception classes, but the fact is they're not integrated into the language at the deepest levels. (Whether that's a good thing or bad is, well, opinion I guess.)

        [Jon]

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2014-07-31 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (242 votes), past polls