http://www.perlmonks.org?node_id=288755


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.