closing the db when an exception was caught