Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Idomatic Handling of Subroutine Error

by btrott (Parson)
on Sep 18, 2001 at 22:50 UTC ( #113171=note: print w/ replies, xml ) Need Help??


in reply to Re: Idomatic Handling of Subroutine Error
in thread Idomatic Handling of Subroutine Error

That's not right. eval BLOCK has no overhead (or rather negligible overhead).

eval EXPR (string eval) *does* have overhead, because the string needs to be compiled at runtime, but that's the issue here.

In general, actually, I would tend to agree with you, but for a different reason: there is no sense in wrapping *every* function call in its own eval. Instead wrap an entire self-contained block in an eval, like this:

eval { ... ... ... }; if ($@) { ## Got error }
You will jump out of the block as soon as your code hits an exception, and you might as well keep your exception-handling in one place, rather than scattered all over the place.

To the OP: check out Exception::Class and Error, among others.


Comment on Re: Re: Idomatic Handling of Subroutine Error
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2015-07-05 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls