in reply to Re: Re: The art of error handling
in thread The art of error handling

The system I have tried to use across the Web site I control, and which I have found particularly useful for DBI work, is:

return($success_ref, $error_ref);

Each subroutine returns either

$dbh->prepare($query) || return (0, "Error: " . $dbh->errstr);

or

return ($array_ref, 0);

You can pepper these throughout your code anywhere there's a DBI action able to fail and it ensures that you can fail somewhat gracefully.

It's not perfect, but it also makes error-checking easy (just test whether $errors contains anything) and allows you to develop a cascading series of calls where it doesn't bother executing subsequent queries if one has already failed.