in reply to Logging the results of 'die'

What may be happening is that your database handle is not being put anywhere out of the eval. (Thus it is being destroyed.)

As for a way to make all dies go to a logfile, reopening STDERR to somewhere else at the beginning of the script could help you:

open STDERR, ">errors.log" or warn "failed to reopen STDERR: $!\n";

(updated because "actual problem" was the wrong phrase where I used it.)

Replies are listed 'Best First'.
Re: Re: Logging the results of 'die'
by no_slogan (Deacon) on Jun 09, 2001 at 01:00 UTC
    Most posts in this thread concentrate on how to catch the error message, but I don't think that's the real issue. wog's message touches on it. The eval should put the database handle somewhere so that a cleanup routine can deal with it in case there's an error. You might try something like this:
    eval { my $dbh = DBI->connect(..., {RaiseError=>1}); eval { $dbh->do("update ..."); $dbh->do("update ..."); }; if ($@) { # clean up after an unsuccessful update $dbh->rollback(); $dbh->disconnect(); die($@); # reraise the error } # successful update $dbh->commit(); $dbh->disconnect(); }; if ($@) { log($@); }