perlexceptionstack-tracedie

Why doesn't Carp verbose produce a stack trace?


Why doesn't use Carp qw(verbose); make die produce a stack trace? I mean that just

ERROR at ./test.pl line 8.

is printed, but I want also a stack trace.

#!/usr/bin/perl

use strict;
use warnings;

use Carp qw(verbose);

sub c { die "ERROR"; }

sub b {
  c;
}

sub a {
  b;
}

a;

Solution

  • Of use Carp qw( verbose );, the documentation says:

    As a debugging aid, you can force Carp to treat a croak as a confess and a carp as a cluck across all modules.

    You don't use croak or carp, so use Carp qw( verbose ); is useless.

    You can achieve what you want by overriding die or by creating a $SIG{__DIE__} handler. Carp::Always is a pre-made solution that does this for you.