$SIG{__DIE__} = sub { return if (defined($^S) && $^S); # in eval return if !defined($^S); # parsing if ($lh) { # this is an initialised Log::Log4perl handle logging to a file local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $lh->fatal($_[0]); } };