mmlenz has asked for the wisdom of the Perl Monks concerning the following question:
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 :)$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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: grabbing un-handled exceptions via modperl2
by Anonymous Monk on May 03, 2013 at 20:44 UTC | |
by mmlenz (Acolyte) on May 06, 2013 at 16:44 UTC |