Restore the context when the exception is thrown