Catch exceptions to restore the error handler