base: improvements of database exception handling

Reviewed-by: Jiri Kuncar <jiri.kuncar@cern.ch>