为什么use Carp qw(verbose);不让die生成堆栈跟踪?我的意思是
错误出现在./test.pl第8行。
是打印出来的,但我也想要一个堆栈跟踪。
#!/usr/bin/perl
use strict;
use warnings;
use Carp qw(verbose);
sub c { die "ERROR"; }
sub b {
c;
}
sub a {
b;
}
a;发布于 2014-06-06 14:21:19
关于use Carp qw( verbose );,文档中说:
作为调试辅助工具,您可以强制Carp将
croak视为confess,将carp视为跨越所有模块的cluck。
您不使用croak或carp,因此use Carp qw( verbose );是无用的。
您可以通过重写die或创建$SIG{__DIE__}处理程序来实现您想要的结果。鲤鱼:永远是为您预先制定的解决方案。
发布于 2014-06-06 08:50:15
发布于 2014-06-06 08:45:25
那么你想要confess
use strict;
use warnings;
use Carp qw(confess);
sub c { confess "ERROR"; }
sub b { c; }
sub a { b; }
a();产出:
ERROR at confess.pl line 6.
main::c() called at confess.pl line 7
main::b() called at confess.pl line 8
main::a() called at confess.pl line 9如果无法更改其他代码,则可以使用$SIG{__DIE__}
use Carp qw(confess);
$SIG{__DIE__} = \&confess;
sub c { die "ERROR"; }
sub b { c; }
sub a { b; }
a();https://stackoverflow.com/questions/24077620
复制相似问题