# Error handling

**URL:** <https://tech-community.robotics.abb.com/t/error-handling/1435>\
**Category:** Robot Controller\
**Created:** [September 17, 2007, 8:31am UTC](https://tech-community.robotics.abb.com/t/error-handling/1435 "2007-09-17T08:31:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DiMo](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@DiMo](https://tech-community.robotics.abb.com/u/DiMo)\
**Post date:** [September 17, 2007, 8:31am UTC](https://tech-community.robotics.abb.com/t/error-handling/1435/1 "2007-09-17T08:31:06Z")

</div>

Hi all,

I have a slight problem with errorhandling in rapid.

In my program there is a gripper test at the beginning of the main routine. Inside the gripper-test-routine I generate an error with the raise statement. In my error handling code I have two choices; one is to try to move the gripper again; second choice is to abort (means ExitCycle). The retry part seems to work.

If the program exits the cycle the gripper test starts again but then rapid comes up with an error message saying an untreated error has occured. I can’t figure out what’s wrong.

Here is what is in the code:

Main-Routine:

proc main()

GripperTest;

endproc

PROC GripperTest()

VAR num i:=0;  
VAR num GripResult := 0;

! – Check if gripper is in position

MoveGripper;  
GripResult := CheckGripperPos();  
IF (GripResult=1 OR GripResult=2 OR GripResult=3) RAISE 10;

ERROR

IF (errno = 10) THEN  
WHILE (Result \<\> 5) DO  
TPErase;  
TPWrite “-- Gripper not in target position --”;  
TPWrite “”;  
TPWrite “You can retry to move the gripper”;  
TPWrite "or abort the current cycle and ";  
TPWrite “move the robot to home position.”;  
TPReadFK result, “Make a choice:”, “Retry”, “”, “”, “”, “Abort”;

IF (Result=1) THEN  
MoveGripper;  
GripResult:= CheckGripperPos();  
IF GripResult=0 TRYNEXT;  
ENDIF

IF (result=5) ExitCycle;  
ENDWHILE  
ENDIF

ENDPROC

---

<div class="post-metadata">

**Author:** ![RobbieRobot](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@RobbieRobot](https://tech-community.robotics.abb.com/u/RobbieRobot)\
**Post date:** [September 19, 2007, 3:38pm UTC](https://tech-community.robotics.abb.com/t/error-handling/1435/2 "2007-09-19T15:38:45Z")

</div>

The fault you are making is the following, when you RAISE an error you have to handle the “error” in the errorhandler. When you exit the cycle you have to use a trynext (or something…) to handle the error.

Otherwise the program shall stop at the point where the error is raised, with an error…

---

<div class="post-metadata">

**Author:** ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://tech-community.robotics.abb.com/u/claudio)\
**Post date:** [September 24, 2007, 5:56pm UTC](https://tech-community.robotics.abb.com/t/error-handling/1435/3 "2007-09-24T17:56:54Z")

</div>

The problem is that your Main() doesn’t have an error handler.  
Even ExitCycle in the error handler is not very beautiful.  
RAISE is helpful in a Error handler because the execution continues in the error handler of the calling function.

For me the best thing is:

Main()

GripperTest;

! Should be something here 😉

ERROR

IF ERRNO=10 THEN  
! Gripper test failed and aborted  
EXIT;  
! Or, RETRY if you’d like to run GripperTest again.  
! Exitcycle is not beautiful.  
ENDIF  
RAISE;  
ENDPROC

PROC GripTest()  
…

ERROR

…

IF (Result=5) RAISE;

ENDPROC

---

<div class="post-metadata">

**Author:** ![DiMo](https://avatars.discourse-cdn.com/v4/letter/d/e9a140/32.png) [@DiMo](https://tech-community.robotics.abb.com/u/DiMo)\
**Post date:** [October 1, 2007, 9:41am UTC](https://tech-community.robotics.abb.com/t/error-handling/1435/4 "2007-10-01T09:41:16Z")

</div>

Hi,

thanks for your replies. That might be right (didn’t have the time to run it on VIRC) - but still I don’t exactly understand why the error is thrown to the main routine. As I understand it I handled the error in the routine where the error was raised. Why does the error occur then in the main routine? I read in the documentation that the error can be raised to the calling routine with an emtpy RAISE statement - but I didn’t do so.

---

<div class="post-metadata">

**Author:** ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://tech-community.robotics.abb.com/u/claudio)\
**Post date:** [October 7, 2007, 1:34pm UTC](https://tech-community.robotics.abb.com/t/error-handling/1435/5 "2007-10-07T13:34:13Z")

</div>

Hi DiMo.

I found the time to check your program in RobotStudio, and say what? It runs. No errors are reported by the robot.  
I have an old version of RobotStudio, and I simulate an IRB140 over an S4C+ controller.  
It will be intersting to test it over a new system. Maybe we are talking about an ABB bug.  
Anyway, I still think it’s not a good idea to exitcycle directly from an error handler. Better to raise back the problem through the calling stack.

Here the version I tested:

MODULE ModMain

PROC main()

GripperTest;

ENDPROC

PROC GripperTest()

VAR num i:=0;  
VAR num GripResult := 0;  
VAR num Result:=0;

! – Check if gripper is in position

!MoveGripper;  
GripResult := 1;  
IF (GripResult=1 OR GripResult=2 OR GripResult=3) RAISE 10;

ERROR

IF (errno = 10) THEN  
WHILE (Result \<\> 5) DO  
TPErase;  
TPWrite “-- Gripper not in target position --”;  
TPWrite “”;  
TPWrite “You can retry to move the gripper”;  
TPWrite "or abort the current cycle and ";  
TPWrite “move the robot to home position.”;  
TPReadFK result, “Make a choice:”, “Retry”, “”, “”, “”, “Abort”;

IF (Result=1) THEN  
!MoveGripper;  
GripResult:= 0;  
IF GripResult=0 TRYNEXT;  
ENDIF

IF (result=5) ExitCycle;  
ENDWHILE  
ENDIF

ENDPROC  
ENDMODULE
