Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Think about Loose Coupling
 
PerlMonks  

Re^3: eval to replace die?

by mjscott2702 (Pilgrim)
on Oct 04, 2010 at 08:44 UTC ( #863287=note: print w/ replies, xml ) Need Help??


in reply to Re^2: eval to replace die?
in thread eval to replace die?

The source of errors isn't always within the script - the "open or die" idiom is used extensively in the documentation, the Camel book etc - for quick scripts, to say, parse a system file and print some useful info, this construct is perfectly suitable - exception handling etc has its place, agreed - but it's a judgement call where that place is.


Comment on Re^3: eval to replace die?
Re^4: eval to replace die?
by chromatic (Archbishop) on Oct 04, 2010 at 14:43 UTC

    I agree that it's difficult to use exception objects pervasively (especially when using other code), and I wouldn't have enabled this rule for Perl::Critic by default myself, but it's very much worth considering the risk and fragility of string comparisons for exception handling.

      the risk and fragility of string comparisons for exception handling.

      Even in Java, it's still "string compare". It's done at compile-time rather than run-time, which is good. But it is still string compare.

      But Exception::Class does not give you that advantage.


      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.

        I should be more precise, you're right.

        Imagine instead I wrote "the risk and fragility of using fuzzy regular expression matches for exception handling, especially when type checks and polymorphism are much more reliable".

Re^4: eval to replace die?
by mjscott2702 (Pilgrim) on Oct 05, 2010 at 08:33 UTC
    Wow, I opened up a whole can of worms there. What I was trying to point out was simply this - sometimes, it doesn't matter WHY something went wrong, just to die gracefully with some informative message e.g. File Not Found.

    In the case of a simple script that is trying to parse a file that it can't access (permissions, missing file etc), there is nothing to recover from - give the user some clue as to what went wrong, and terminate.

    Obviously, there are situations where the script/application/program shouldn't exit - trap the error, display the error message, log it and continue.

    The use of eval, catching exceptions, trapping signals etc is the choice of the programmer - TMTOWTDI.

    And yes, that might mean some fuzzy string comparisons.... :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-04-19 05:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (478 votes), past polls