in reply to Catching error in DateTime::Format

A simple die prints $@ of last failed eval, even without explicitly telling it to do so. And that's confusing if you decided to move on from the failed eval and then you throw a die and it talks about past things... Perhaps something else in the code or Test::More does similar?

use strict; use warnings; use DateTime; my $x = eval{ DateTime->from_epoch(epoch=>'xxxx'); }; print "xx\n"; die; # moving on to other business: my $z = 1; #eval { 1 }; # "reset" $@ die; # still displays the $@ of last failed eval which is irrelevant a +t this point in the code!

Replies are listed 'Best First'.
Re^2: Catching error in DateTime::Format
by Anonymous Monk on Oct 28, 2025 at 13:16 UTC

    OP here. Wow, yes, that was it! I put a "die" in there so I could study this one test while I was working on it. When I removed that, the tests worked as normal. And of course I didn't show the entire test suite in my example here, so I didn't include the "die" at the end of the relevant section.

    Thank you so much! I never, ever would have figured that out. (In fact, it would have been even more confusing after I'd removed the "die" to run the complete test suite, and the test started working fine.)

      hehe, die never moves on. Unless you reset $@ with reset('@'); prior to calling die, after your eval.

        Unless you reset...
        But don't do that.