How to catch event 50139 in a RAPID program

When a RAPID program makes the robot arm grab a specific target, while waiting for the gripper to close, the robot arm keeps moving forward with the conveyor, which maybe trigger a 50139 event and stop. I want to catch the 50139 error in the RAPID program, then clear the error and move arm to a safe position.

How should I do this?