Do I need the 1; ?
Generally, yes, you should include it. The reason is that eval returns undef on failure, which is what the or do { ... } is intended to react to. However, the or would also be triggered if the eval block were to return any other false value, such as 0 or the empty string. For example, the following incorrectly prints "Error from Module::That::Dies:". So unless you can be absolutely sure that the eval block always returns a true value, you should include the 1 (or any other true value) as the last statement of the block.
sub Module::That::Dies::die_here { return 0 } eval { Module::That::Dies::die_here(); #1; } or do { warn "Error from Module::That::Dies:\n$@\n"; };
Update: I tend to write it like the following, since the 1 on a line by itsself can look out of place and might be accidentally deleted:
eval { ... ;1 } or do { # catch ... }
In reply to Re^3: Can I catch a die from someone else's module?
by haukex
in thread Can I catch a die from someone else's module?
by bartender1382
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |