Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://113171]
help
Chatterbox?
[Corion]: Meh, I found another Amazon "used" scam reseller... If a product sells for "almost new" at half the price, it's a scam, most likely...
[ambrus]: Corion: that's not true. Actually for Christmas and Thanksgiving, a lot of people buy electronics such as cameras as present, then many of them figure out they don't need it,
[ambrus]: and the electronics gets reselled almost new, but it has to be sold at half price because otherwise everyone chooses to buy the new product which has fewer risk of selling damaged products labelled as almost new.
[ambrus]: You can actually get a lot of useful cheap really almost new products that way, with only a little risk of scams.
[ambrus]: That's what some of the "Black Friday" sales are about.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2017-11-21 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (304 votes). Check out past polls.

    Notices?