Handling errors the smart way
Life after death:
$h->{RaiseError} = 1;
eval {
foo();
$h->method; # if it fails then the DBI calls die
bar($h); # may also call DBI methods
};
if ($@) { # $@ holds error message
... handle the error here …
}
Bonus prize:
- Other, non-DBI, code within the eval block may also raise an exception that will be caught and can be handled cleanly