We have a legacy web app that runs under ModPerl::RegistryPrefork and it works well. We use some code to log unhandled errors (that would result in a 500 response error). This code resides inside the modperl startup script and is something to the effect:
$SIG{__DIE__} = sub { my $error = shift; my $i = 0; my $caller = ''; while (my (undef,$file,$line,$sub) = caller($i++)) { $caller .= "Line $line of file $file called $sub\n"; } my $from_address = "blah@blah.com"; my $mailer = MIME::Lite->new( 'From' => $from_address, 'To' => $ENV{SERVER_ADMIN}, 'Subject' => 'ERROR on '. "$ENV{'SERVER_NAME'}", 'Data' => "When: ". scalar(localtime(time())). "\n\n". "Program: $ENV{SCRIPT_NAME}\n\n". "Error:\n$error\n". "Call Trace:\n$caller\n". "Environment Variables:\n". join("\n", map("$_ = $ENV{$_}", keys(%ENV))) ); $mailer->send_by_sendmail(SetSender => 1); }
Back when this code ran under modperl 1.x (many years ago) this worked great and we were only notified of actual system errors (500). It still works for modperl 2.x but we get a notification for EVERY exception in any code "use'd", not just system errors. I'd posted about this on a different forum sometime back and people came up with a few ideas with relation to checking return codes directly in apache2 mod perl or using a custom ErrorDocument 500 cgi and some ideas about using Perl*Handlers but the issue was that we couldn't see the call stack (which for obvious reasons is incredibly useful) for the code in question. I know this is probably too modperl/apache2 specific but I figured I'd try the monks :)

In reply to grabbing un-handled exceptions via modperl2 by mmlenz

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.