in reply to Re: Re: Error Handling in Object-Oriented Perl
in thread Error Handling in Object-Oriented Perl

I don't know about best practices, but I do this all the time...

eval { ... } if( my $err = $@ ) { die $err; }

However, I tend to make my code propagate most of fatal errors all the way up to the user, unless there is some compelling reason that the error must be trapped in that particular level. I trap and re-throw in mostly in cases when I want to add more logging information than $@ would otherwise contain... otherwise I just let it propagate.

... and since that "compelling reason" varies from application to application, I don't have a general solution :(

Replies are listed 'Best First'.
Re: Re: Re: Re: Error Handling in Object-Oriented Perl
by Joost (Canon) on May 24, 2002 at 16:09 UTC
    I think a little more idiomatic construct would be:

    eval { ... } die if $@;
    Which will propagate the $@ (appending "... propagated" if $@ is a string, and calling $@->PROPAGATE() if $@ is an object, and then issuing die $@ (this is only documented from perl 5.6, so it might not work like this on older perls...)

    See also:

    perldoc -f die
    -- Joost downtime n. The period during which a system is error-free and immune from user input.

      Ha! Learn something new everyday ;) thanks for the pointer :)