Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Nested evals - are they evil?

by eyepopslikeamosquito (Chancellor)
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://629763]
[Discipulus]: good morning nuns and monks!

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-05-22 06:31 GMT
Find Nodes?
    Voting Booth?