Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Update 2:The latest bleaperl has a patch that allows
perl -Mdiagnostics=t-,-w badly_behaved_script
-w adds stack traces to warnigns and -t turns off the explanations. No need for a new module.

Update:I should have been more clear in my question, I'm not asking "how do I do this?", I already know how to do it. I'm asking "is this readily available already?" because it's pretty amazing that after all these years, there is no standard, easy way to force Perl to give a stacktrace when it dies.

In particular I want to be able to say to someone who's using my code and having problems, "run it again with perl -MDevel::Verbose and send me the output" and they'll be able to get it from CPAN and the code should work just as before, except with much more info when it dies.

Most languages will give you a stack trace when they die or at least you can set a flag so that this happens, Perl lacks this feature and I couldn't find a module that provides it. So for quite a while now I have been using my own module that works like this

use Devel::Verbose; a_sub(); sub a_sub { will_warn(); print STDERR "-------------\n"; will_die(); } sub will_warn { warn("something funny"); } sub will_die { die("something awful"); }
this will give output something like
Trace begun at line 11
main::will_warn at line 5
main::a_sub at line 3
something funny at line 11.
Trace begun at line 14
main::will_die at line 7
main::a_sub at line 3
something awful at line 14.
It's very careful not to interefere with the original dieing and warning behaviour (it's not perfect in this respect but it's close).

Have I reinvented a wheel? Just checking before I post to CPAN. It's based on Devel::StackTrace and Exception::Class.

Carp does something similar but you have to explicitly use it in your code, whereas I can do perl -MDevel::Verbose and I will get full stack traces from all warn()s and die()s, without changing a line of code in

In reply to Automatic stack traces for warns and dies by fergal

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (4)
    As of 2021-03-04 21:57 GMT
    Find Nodes?
      Voting Booth?
      My favorite kind of desktop background is:

      Results (108 votes). Check out past polls.