in reply to Re^3: How to print the backtrace in a "catch" block?
in thread How to print the backtrace in a "catch" block?

I looked at some of my code...
It is possible to install a localized $SIG handler.
In my case a stack trace means next to nothing..I want to know the exact DB record the failure happened on..that means something!

In this code, I just have a __WARN__ handler, but I would presume that __DIE__ would be possible also. Of course $x has to be in scope for the $SIG handler!

Anyway, installing a __DIE__ handler in the sub() might be easier and even better than a stack trace - although that could be done in the handler also. In this code, I just want to know which of 1M DB records caused the Warning - its not fatal for this code, but it is something I have to find and fix later. Just an idea....

sub x { my ($x) = @_; # $x is an array ref to a DB record local $SIG{__WARN__} = sub { my $msg = shift; print STDERR "*******\n"; print STDERR $msg; print STDERR "current DB record: id=", $x->[ID]; }; # some stuff that might cause a Warning.... # some operations on the record pointed to by $x # maybe "abc123" is not numeric, etc. return $result; }