Suppose you set up the following:

use Data::Dumper qw(Dumper); $SIG{__WARN__} = sub { &handle_it(@_); warn @_ }; $SIG{__DIE__} = sub { &handle_it(@_); die @_ }; sub handle_it { print Dumper \@_; }


Everything looks great. Should be able to spit out arguments that were passed. Except the following happens:

die "foo"; # prints as "foo at script line whatever\n" - stringifie +d #die "foo", "foo"; # stringified - same as above but with "foofoo" #die {hi => 'there'}; # not stringified - shows correctly as a hashre +f #die 'foo',{hi => 'there'}; # stringified "fooHASH{whatever}" #warn {hi => 'there'}; # always stringified


So, rather than being able to have useful handlers, we are left with a mess. Granted the one case that didn't stringify is great for Object Exceptions like die My::Exception->whatever('foo'), the reason for stringifying in the other cases is mind boggling. It seems that perl should leave the arguments alone until somebody calls die from inside a $SIG{__DIE__} handler or warn from inside the $SIG{__WARN__} handler. I'm sure its all an "internals" issue but still it seems like a poor choice to almost, but not quite, provide the data that was passed along.

So my question. Is there a way turn off stringification entirely for this case. I know that I could send an object as a parameter with a better overloaded stringification mechanism - but that is overkill. I'd love to be able to do:

die "Something happend", {extra_argument_to_show_pretty_error => 1};


I haved looked but my guess is I get to wait for Perl 6 Exceptions.

Thanks for any help.

my @a=qw(random brilliant braindead); print $a[rand(@a)];

In reply to Argument stringification in __WARN__ and __DIE__ by Rhandom

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.