Thanks Brian and Vitor,
I ended up using the HandleError route and that seems to work well. Using a
connection string like:
$dbh = DBI->connect("$dsn","$dbuser","$dpassword",
{RaiseError=>0,
PrintError=>0,
AutoCommit=>1,
HandleError=>\&errorsub})
or die "Unable to open database:\n\n$DBI::errstr\n";
I can specify a subroutine to call when a DBI error occurs. DBI passes the
error string, database handle and failed function return value to the
subroutine specified in 'HandleError'.
To get additional information about the error I now also use the value of
'Carp::longmess' to get the full details, including stack trace, of the
error.
Cheers,
Bill
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Brian
Raven
Sent: 19 May 2005 17:34
To: activeperl mailing list
Subject: RE: DBI - saving the contents of PrintError
Bill - compuserve wrote:
> Hi All,
>
> I'm using DBI and am currently trying to set up an error logging
> system to catch DBI errors. I'd like to use the automatic error
> trapping provided by DBI so I'm using a connection call like this:
>
> $dbh = DBI->connect("$dsn","$dbuser","$dpassword",
> {RaiseError=>1,
> PrintError=>0,
> AutoCommit => 1})
> or die "Unable to open database:\n\n$DBI::errstr\n";
>
> When an error happens though what I'd like to do is save the error
> message in a file and trigger an email. Is it possible therefore to
> have the DBI call a user specified subroutine when an error occurs,
> instead of just dying, and pass to that subroutine the full error
> message which gets sent to the concole - includeing script name, line
> number, error string etc.
>
> I'd appreciate any suggestions on this one.
See 'perldoc DBI'. Search for 'HandleError'.
HTH
--
Brian Raven
-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely
for the intended addressee(s). Unauthorised reproduction, disclosure,
modification, and/or distribution of this email may be unlawful. If you
have received this email in error, please notify the sender immediately
and delete it from your system. The views expressed in this message
do not necessarily reflect those of LIFFE Holdings Plc or any of its
subsidiary companies.
-----------------------------------------------------------------------
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs