CRM-11926 add a better error handling for db errors in the api

YEAP! only this single commit this time.

So to get it clean:
git fetch civicrm  master:name_of_your_feature (CRM-11926_upstream in this case)
git checkout name_of_your_feature
do the modifications, git cherry-pick sha of the commit you want from your other branches

!!! git status says you are ok
git push name_of_your_feature

and pull request

Trivial, isn't it? ;)