in reply to Error.pm vs closure issue fixed in Perl > 5.8.4 ?

That problem does seem to be fixed, but returning from inside a try block is still a problem (and not fixable as long as try blocks are implemented as sub refs), so I would still avoid this module. See Re: Re2: Learning how to use the Error module by example for a full example and look at Exception-Class-TryCatch for an alternative.
  • Comment on Re: Error.pm vs closure issue fixed in Perl > 5.8.4 ?

Replies are listed 'Best First'.
Re^2: Error.pm vs closure issue fixed in Perl > 5.8.4 ? (return)
by tye (Sage) on Sep 02, 2008 at 20:42 UTC
    but returning from inside a try block is still a problem (and not fixable as long as try blocks are implemented as sub refs),

    returning from a 'try' block is not fixable at all. Because 'try' has to be implemented via eval and return in an eval just leaves the eval, it doesn't return from the enclosing subroutine. So this particular problem is a problem with Perl(5)'s implementation of exceptions and not at all a problem specific to Error.pm.

    For the problem with Error.pm, s/try/catch/g on your statement:

    but returning from inside a catch block is still a problem (and not fixable as long as catch blocks are implemented as sub refs),

    - tye        

      Interesting, I thought that eval would allow a return, but you're right, it doesn't. So there are two problems that prevent this from working intuitively with return statements and neither of them have any known fix in Perl 5.