in reply to Which incarnation of try/catch to use?

IMHO, Try::Tiny is the "best" (simplest, most portable) module. Like Haarg, I am wondering what you mean by "eval { } can't do that" - one of the simplest ways to do try/catch built in to Perl is eval { ...; 1 } or do { ... }; (but not eval { ... }; if ($@) { ... }!)

Replies are listed 'Best First'.
Re^2: Which incarnation of try/catch to use?
by mldvx4 (Friar) on Oct 03, 2023 at 07:49 UTC

    Aha! There was one of the problems, I had been using eval { ... }; if ($@) { ... } instead of eval { ...; 1 } or do { ... }; and the latter worked as intended, trapping the error raised in a deeper module by bad data. I've tracked down the cause of my script making the bad data now but have to redesign a bit of the work flow.

    After that, I folded the core "try" feature now, with good results. Although the script now warns that "try" is experimental.

      Although the script now warns that "try" is experimental.

      See the sample code in New built-in perl5.38 try/catch syntax that silences the warning via:

      # use feature 'try'; # throws 'try/catch is experimental' warnings use experimental 'try';