Hi,
On Tue, 30 Oct 2001, Guy Tubbs wrote:
> Does anybody know if it is possible to trap errors in Perl when they occur
> and then send them with a bit of info with sendmail?
Sure it is. In fact, you always want to trap errors in a web app so you
can die gracefully and give the user some nice message rather than an icky
server error page.
> For example, if one of my web scripts messed up when someone was using it
> they'd get the standard error page and I would receive an email with the
> referring page and any other useful info as to why the problem occurred.
I use a custom error routine in my web apps. Say a database error occurs,
I tell the user, in a pretty web page, that the database is temporarily
unavailable, but I log the real error. I could also email it to myself.
sub db_down {
# if the db connections fail
my ($err) = shift;
print qq!The database is temporarily unavailable.<P>\n!;
print qq!</BODY></HTML>\n!;
my $date= scalar localtime();
if (open (LOG, ">>$logfile") ) {
print LOG "$0: $date: $err\n";
close (LOG);
}
exit (0);
}
Where I print to a log file, I could email using nice modules for that
purpose, or I could (safely) use the old pipe to sendmail.
I call this routine for example, like this, to trap a bd error:
$sth->execute or db_down ($DBI::errstr);
-lisa
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]