good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^2: eval failure does not set $@by haukex (Archbishop) |
on Jun 06, 2018 at 20:51 UTC ( [id://1216059]=note: print w/replies, xml ) | Need Help?? |
Only if the code you are executing "dies" or throws a warning, in the perl sense, would eval return something in $@. But as I wrote, there are cases where the code in the eval can die, and $@ doesn't get set (Update: or to be more specific, gets clobbered so that it's no longer available after the eval). A simple demo of this bug:
Even on Perl 5.26, this only prints "Hello<>". That's why the eval { ...; 1 } or do { ... }; pattern is better - choroba showed how that pattern still works even in the presence of a similar bug on Perls <5.14 here. If the routines you are running return a status, then you want to catch that status coming back from eval I would suggest writing it this way, where of course 3+4 is a stand-in for something more complex (and it may also be a false value):
In Section
Seekers of Perl Wisdom
|
|