Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Error Handling Misconception

by gjb (Vicar)
on Sep 03, 2003 at 22:27 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://288755]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-26 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found