Handling the error event