Like japhy said, look into Carp. However, it sounds like that isn't what you're looking for...are you saying that none of your die messages include any line/filename info? In that case, this suggests that your die() message strings all end in '\n'. If you remove those newlines, you'll get that information. Alternatively, if you replace each die() with croak(), the '\n' won't prevent a line-number from appearing (although it will push that information onto the next line). As an alternative, rather than going line-by-line through your code, just adding this should give you what you want:

BEGIN { $SIG{__DIE__} = sub { my $string = shift; chomp($string); my ($package, $file, $line) = caller; die "$string [at $file, line $line]\n" unless ($package eq 'Carp'); } }

Modifying $SIG{__DIE__} like this changes how all of your die() calls behave (including croak(); that last bit with the 'unless' is in there to keep the output from getting too ugly). If you want the same sort of thing for warn() and carp(), you can modify $SIG{__WARN__}.

Update: I had croak() and carp() switched in the last paragraph there (thanks premchai21).

Update++:Also, tilly's post above this one (about checking $^S) applies to what I'm doing here. Here's how I think this ought to be taken into account (with confess thrown in for a complete trace of the call-stack (thanks again tilly)):

BEGIN { $SIG{__DIE__} = sub { my $string = shift; chomp($string); my ($package, $file, $line) = caller; confess "$string\n" if ((defined ($^S)) and not $^S); } }
Note that I'm going on what I just read in perlvar more than on experience with $^S. Also, using confess in $SIG{__DIE__} like this produces a little weirdness in the output when you use croak in the main code, that I don't know how to fix.

-- Frag.


In reply to Re: dying() more informatively by frag
in thread dying() more informatively by thpfft

Title:
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, details, 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, summary, 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.