As already noted, CGI::Carp will do exactly what you asked for, but...
Consider carefully the wisdom of doing so. Many of us don't use CGI::Carp on sites which will be exposed to the public because detailed information about how and why the code failed could be very helpful to an attacker who wished to compromise the site by deliberately causing it to fail and, perhaps, even help him engineer the means to cause it to fail in a specific manner for his advantage.
CGI::Carp is a handy development tool (especially when you don't have direct access to the server logs), but you'd probably be better off using a more verbose construct which lets you tell the user information which is both safe for you and useful for him1. Maybe even recover from the error and go on instead of dying. Something like:
unless (my $address = retrieve("/tmp/$session_file")) {
warn "no session file $!\n";
create_new_session_file("/tmp/$session_file");
redirect_user_to('new_session_page');
}
1 OK, so the user knows there his session file should have been at
/tmp/blahblahblah. What can he do about it and how does this knowledge benefit him in any (legitimate) way?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.