In my experience, it's generally not a good idea to leave FatalsToBrowser enabled in production code. There's a lot of discussion of this elsewhere in the monastery, and so I'll not delve into that. I'll also not ask you why are you putting code in a production environment with errors such as that ;)

My lecturing aside. . . check the CPAN documentation for CGI::Carp. There's an excellent example of creating your own error message featured there. I'll repeat it here, however it's no substitute for reading the actualy documentation:

use CGI::Carp qw(fatalsToBrowser set_message); BEGIN { sub handle_errors { my $msg = shift; print "<h1>Oh gosh</h1>"; print "<p>Got an error: $msg</p>"; } set_message(\&handle_errors); }
In a production environment, I remove FatalsToBrowser and instead replace it with custom error handling (and don't let the code go out with compile errors ;) Statements I've known to fail from time to time (database calls, etc.) I instead wrap in an eval block:
eval { $sql = $dbh_receipt->prepare_cached($script); $sql->execute(); $sql->bind_columns(\$receipt); $sql->fetch(); $sql->finish(); }; if($@) { log_error($dbh_receipt->err(), $dbh_receipt->errstr(), $script); }
By processing my own errors, I control exactly what the user sees, and can then log them to a database and even e-mail them to myself so I can look like a good guy to my users when I fix their problems before they have a chance to call me about them.

Granted, this might be overkill for what you are trying to do, and I've probably strayed too far OT from the original question, but you get the point ;)

Hope this helps!
MrCromeDome


In reply to Re: Changing default carp error message by MrCromeDome
in thread [untitled node, ID 182637] by Samn

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.