Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Nested evals - are they evil?

by eyepopslikeamosquito (Canon)
on Jul 31, 2007 at 08:11 UTC ( #629763=note: print w/ replies, xml ) Need Help??


in reply to Nested evals - are they evil?

As convincingly argued in Perl Best Practices, Chapter 13 (e.g. first guideline is "Throw exceptions instead of returning special values or setting flags"), generally you should embrace exception handling.

However, having each method simply catch and rethrow exceptions does seem evil ... or at least pointless. Maybe there was a historical reason for this? Is there technical documentation for this system describing why this is being done and, more importantly, describing a rational and consistent error handling policy for the system as a whole?

Generally, throwing should be done when a method detects an error that it cannot resolve itself and catching should be done where there is sufficient knowledge/context to sensibly handle/report the error. Catching just to rethrow seems warranted only at "system boundaries" (e.g. translating a low level error message into a higher-level one); if a method isn't going to handle, translate, or intentionally ignore the error itself, it should simply let it propagate upwards to a caller who can.


Comment on Re: Nested evals - are they evil?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2014-09-02 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (20 votes), past polls