in reply to Re: Can I catch a die from someone else's module?
in thread Can I catch a die from someone else's module?
eval { Module::That::Dies::die_here(); 1; } or do { warn "Error from Module::That::Dies:\n$@\n"; };
bartender1382: I just wanted to highlight that eval { ...; 1 } or do { ... } is indeed the correct pattern to use, instead of the unfortunately still common eval ...; if ($@) - see Bug in eval in pre-5.14 and my reply Re: Bug in eval in pre-5.28. In fact, this use of eval is very similar in function to Try::Tiny. The latter just has a few small advantages as described in its documentation, while the eval solution has the advantage that it is pure Perl built-in (Update: Try::Tiny is pure Perl too, but not a core module).
|
|---|