in reply to dbi: PrintError and RaiseError
I usually use RaiseError as it allows me not to check error condition after every DB operation. If I don't want script to die after error I always can catch exception. Compare these examples:
$dbh->do(...) or handle_error(); $dbh->do(...) or handle_error(); $dbh->do(...) or handle_error(); $dbh->do(...) or handle_error();
or
eval { $dbh->do(...); $dbh->do(...); $dbh->do(...); $dbh->do(...); } if($@) { handle_error(); }
But sometimes you have to mix db operations with others and you want to be able to distinct db errors from lets say IO errors. In this case RaiseError may be not so convenient. E.g.:
use Fatal qw(open); eval { $dbh->do(...); open my $fd, "<", $file; # some other stuff } if($@) { # and here we can't say if it was DBI problem or open }
|
|---|