Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Error Handling Misconception

by gjb (Vicar)
on Sep 03, 2003 at 22:27 UTC ( #288755=note: print w/replies, xml ) Need Help??


in reply to Error Handling Misconception

To catch die's with eval, the eval block must be terminated with a semi-colon.
So you'd better be off rewriting the while as

for (;;) { my $value = eval { $object->next_val() }; if ($@) { print "Error: $@\n"; next; } last unless $value; # do something useful... }

Hope this helps, -gjb-

Update: Althought chromatic puts it very politely, he's dead right: the semi-colon stuff above was nonsense. Thanks chromatic for making me think twice.

Replies are listed 'Best First'.
Re: Re: Error Handling Misconception
by chromatic (Archbishop) on Sep 03, 2003 at 23:09 UTC
    To catch die's with eval, the eval block must be terminated with a semi-colon.

    Do you have a source for this?

    sub dies { die "That's it!"; } if (eval { dies(); 1 }) { print "No death!\n"; } else { print "Death caught: $@\n"; }
Re: Re: Error Handling Misconception
by perrin (Chancellor) on Sep 04, 2003 at 01:19 UTC
    You probably got that idea about the semi-colon from the Error module which uses sub refs to implement a try/catch syntax. The sub refs do require a semi-colon.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2020-06-06 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (41 votes). Check out past polls.

    Notices?