in reply to style for returning errors from subroutines

Well, maybe I've been spoiled by the nice exception handling in Smalltalk, but I like not having to pass error values around everywhere, test them every time, and so on.

You might like to look at the Exception module, which provides a structure similar to the exception handling in C++. It uses a __DIE__ handler, so it also catches regular die() events. Some examples (loosely from the manpage):

# to raise an exception (simply): Exception->raise('text'); # to trap exceptions 'foo', /bar/, or 'baz': my $err=new Exception 'baz'; try { something_that_could_raise_an_exception(); } when ['foo', qr/bar/, $err], except { shift->croak; };
You can also re-raise exceptions, transform them, and use finally blocks. It is something worth looking into...

update:Yes, I meant Exception-1.4. What part didn't match?

Replies are listed 'Best First'.
Re: Re: style for returning errors from subroutines
by John M. Dlugosz (Monsignor) on Jun 14, 2001 at 20:36 UTC
    That CPAN link points to 45 modules called Exception. Which/whose are you suggesting? (The one called Exception-1.4 doesn't match your example).