dynamo has asked for the wisdom of the Perl Monks concerning the following question:

Fellows, I'm not getting enough info from die messages, especially when they happen in subroutines I didn't write. I need the call stack, like I'd get from a call to croak, but I want to GLOBALLY change all dies to croaks so I don't have to rewrite all the libraries I use etc.. What's the best way to do this? Is it really as simple as something like:
package CORE; use Croak; sub die { croak @_ }
Or would I be better off looking at symbol table manipulation, or what? Thanks in advance.

Replies are listed 'Best First'.
Re: Need Increased Funeral Verbosity
by Fletch (Bishop) on Feb 18, 2006 at 03:16 UTC
    use Carp qw( croak ); $SIG{__DIE__} = sub { croak @_ };
      Thank you! This looks perfect.
Re: Need Increased Funeral Verbosity
by GrandFather (Saint) on Feb 18, 2006 at 09:37 UTC

    use diagnostics prints a call stack to STDERR when nasty things happen:

    use warnings; use strict; use diagnostics; use Benchmark qw(cmpthese); callCmp (); sub callCmp { cmpthese (1, {bogus => cmpthese, bogus => cmpthese}); }

    Prints to STDERR:

    Uncaught exception from user code: usage: cmpthese($count, { Name1 => 'code1', ... }); or cmpthese($count, { Name1 => sub { code1 }, ... }); or cmpthese($result, $style); at C:/Perl/lib/Benchmark.pm line 876 Benchmark::cmpthese() called at noname1.pl line 10 main::callCmp() called at noname1.pl line 7

    DWIM is Perl's answer to Gödel
Re: Need Increased Funeral Verbosity
by saintmike (Vicar) on Feb 18, 2006 at 03:11 UTC
    Here's a trick for Log4perl. You could put a LOGCONFESS() in the warn/die handlers instead if you need a stack trace:
    use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($DEBUG); $SIG{__DIE__} = sub { $Log::Log4perl::caller_depth++; LOGCONFESS @_; }; Foo::badsub(); package Foo; sub badsub { die "Argh!!"; }