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

Re: Style Point: Catching eval { } errors

by diotalevi (Canon)
on Nov 24, 2003 at 21:23 UTC ( #309696=note: print w/replies, xml ) Need Help??


in reply to Style Point: Catching eval { } errors

Even better, don't depend on $@.

eval { # Do stuff 1; } or do { # Handle errors };

I commonly write this to bring in $@ without being obfuscatory.

eval { ... ; 1} or die "Barfoo ... $@";

Replies are listed 'Best First'.
Re: Re: Style Point: Catching eval { } errors
by DapperDan (Pilgrim) on Nov 25, 2003 at 19:24 UTC
    I don't remember seeing any reference to this in the documentation for eval. If their were I would have used it.

    Perhaps it should be there? It seems to me that eval {} or do {} is the perfect idiom for using eval with exceptions.

      perldoc -q eval
      In both forms (eval EXPR / eval BLOCK), the value returned is the value of the last expression evaluated inside the mini-program; a return statement may be also used, just as with subroutines. The expression providing the return value is evaluated in void, scalar, or list context, depending on the context of the eval itself. See "wantarray" for more on how the evaluation context can be determined.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://309696]
help
Chatterbox?
[ambrus]: Corion: what I don't understand is, if you make a one-shot AnyEvent timer with short timeout, does this code guarantee that the Prima timer can't queue two timeout events before invoking any of them?
[ambrus]: Because that could break AnyEvent code, which is why I added a guard.
[ambrus]: (It might be easier to use the callback scalar as a guard, as in $c and &$c(); $c = ();)
[Corion]: ambrus: Hurr - yes, that might happen, as Prima will queue lots of stuff (Well, Windows will)
[Corion]: But I'm really amazed that it just took this little code (plus the idle handler I have in mind and something else dk suggested)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2016-12-09 09:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (150 votes). Check out past polls.