in reply to How to prevent exception stringification after error in require/use?
Why not do:
my $base_class = '...'; # base class for exceptions my $error_class = '...'; # my error class sub fixerror(;$) { my $e = @_ ? $_[0] : $@; return $e if blessed( $e ) && $e->isa( $base_class ); return $error_class->new( $e ); } sub try(&) { my $code = $_[0]; eval { &$code() }; $@ ? fixerror($@) : undef; }
That way you don't have a callback that has the potential of getting called multiple times.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to prevent exception stringification after error in require/use?
by thenaz (Beadle) on Aug 04, 2011 at 15:44 UTC |