Logging causes of database exceptions