in reply to Re^3: Where did $@ go?
in thread Where did $@ go?

That's what I'm thinking too: The overloaded bool for the object itself must contain eval blocks.

So, the classic code as shown in the Camel Book simply can't work. If you don't use Try::Tiny (or compatible system? Do they interoperate properly?), you can only use $@ once.

Now, as I'm updating my idioms, I'll just use Try::Tiny. And if editing old code, it might be necessary to assign $@ to a local first, and change subsequent uses. If a function changes so it throws a fancy object now, or uses Moose in the new version, old code that calls something that calls something that calls the function which throws an exception will be broken.

IMO, This specific case (stringification and boolification of the exception object) should take more care not to clobber $@. After all, one of the things Try::Tiny claims to do is localize $@. The guts of the Failure object needs to use that!

Replies are listed 'Best First'.
Re^5: Where did $@ go?
by JavaFan (Canon) on Mar 22, 2011 at 07:27 UTC
    So, the classic code as shown in the Camel Book simply can't work. If you don't use Try::Tiny (or compatible system? Do they interoperate properly?), you can only use $@ once.
    Once? Try not at all. See the other messages in this thread. Pre-5.14, $@ is unreliable (and post 5.14, your problem won't magically solve itself - and I doubt Try::Tiny can determine why a block died without looking at $@). Never use $@ to determine whether an eval succeeded or not. Just use its return value. I'm not saying one shouldn't use Try::Tiny, but I do want to point out that safely determining whether an eval succeeded or not does not require a module:
    eval { ... your code goes here ... 1; } or do { my $err = $@ || "Unknown error"; ... error handling ... };
Re^5: Where did $@ go?
by ikegami (Patriarch) on Mar 22, 2011 at 07:02 UTC

    This specific case (stringification and boolification of the exception object) should take more care not to clobber $@.

    And handling of other cases is improved in 5.14.