When using use strict perl will generate a runtime error on unsafe constructs. Now I am wondering if it is possible to have it only print a warning instead of c
The preferred method:
use Carp;
sub foo {
croak "no args" unless @_;
}
eval foo();
if( $@ ){
print "caught die: $@";
}
If you can't change your die's to croak's:
sub foo {
die "no args" unless @_;
}
{
my $prev_die = $SIG{__DIE__};
$SIG{__DIE__} = sub { print "caught die: $_[0]"; };
eval foo();
$SIG{__DIE__} = $prev_die;
}
The second method will print out the errors on STDERR.
See:
perldoc -f eval
perldoc perlvar and search for /\$\@/ and /__DIE__/
perldoc Carp