Add exception handling for db.