in reply to Re^2: Rethrowing with die $@ considered harmful
in thread Rethrowing with die $@ considered harmful

Does bar() throw an exception itself?

Getting away from working with $@ directly is one reason why I wrote Exception::Class::TryCatch -- the try keyword on eval isn't just sugar, it saves away $@ onto a stack for a later catch. That way, it can even be nested. E.g.

use Exception::Class::TryCatch; try eval { Exception::Class::Base->throw('error') }; # can eval or use try/catch again regardless of $@ above bar(); catch my $err; # catches the matching "try"

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.