Added exception handling on the database