Added error handling for the exceptions that the default handler doesn't catch.