Exception handling in database class