LanX has asked for the wisdom of the Perl Monks concerning the following question:
Anything wrong with this approach to conditionally force a stacktrace with legacy code ?
I know that there is Carp::Always , but it warns that it's manipulating the SIG-handlers and doesn't play well along other modules doing so.
use strict; use warnings; use Carp; use constant ERR_BACKTRACE => 1; BEGIN { if (ERR_BACKTRACE) { *CORE::GLOBAL::warn = \&Carp::cluck; *CORE::GLOBAL::die = \&Carp::confess; } } sub t2{ warn "warn with trace"; } sub t1 { t2(21,22,23); die "die with trace"; } t1(11,12,13);
-->
Compilation started at Fri Sep 27 15:18:09 C:/Perl_524/bin\perl.exe d:/exp/t_carp.pl warn with trace at d:/exp/t_carp.pl line 17. main::t2(21, 22, 23) called at d:/exp/t_carp.pl line 21 main::t1(11, 12, 13) called at d:/exp/t_carp.pl line 25 die with trace at d:/exp/t_carp.pl line 22. main::t1(11, 12, 13) called at d:/exp/t_carp.pl line 25 Compilation exited abnormally with code 255 at Fri Sep 27 15:18:10
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Forcing stacktrace, alternative to Carp::Always
by tobyink (Canon) on Sep 27, 2019 at 13:53 UTC | |
|
Re: Forcing stacktrace, alternative to Carp::Always
by jcb (Parson) on Sep 27, 2019 at 21:41 UTC | |
by LanX (Saint) on Sep 27, 2019 at 23:09 UTC | |
by LanX (Saint) on Sep 28, 2019 at 15:34 UTC |