# RAISE and ERROR from TRAP ROUTINE

**URL:** <https://tech-community.robotics.abb.com/t/raise-and-error-from-trap-routine/10675>\
**Category:** RobotStudio\
**Created:** [April 5, 2022, 1:16pm UTC](https://tech-community.robotics.abb.com/t/raise-and-error-from-trap-routine/10675 "2022-04-05T13:16:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![enriquetracker](https://avatars.discourse-cdn.com/v4/letter/e/ce73a5/32.png) [@enriquetracker](https://tech-community.robotics.abb.com/u/enriquetracker)\
**Post date:** [April 5, 2022, 1:16pm UTC](https://tech-community.robotics.abb.com/t/raise-and-error-from-trap-routine/10675/1 "2022-04-05T13:16:28Z")

</div>

I am trying to raise an error from a TRAP routine, I achieve this when in the upper routine the error is handled in this way:  
ERROR(MY\_ERROR)  
…ACTIONS…

However, when I have more than one error handled and I have to handle it this way:

ERROR  
IF ERRNO=MY\_ERROR THEN

I get that the error is not controlled. I don’t know what to do.  
The trap routine is handled like this:

TRAP t\_trap\_Empty

RAISE err\_empty\_stop;

ERROR  
RAISE;

ENDTRAP

Thank you very much!!!

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [April 5, 2022, 1:45pm UTC](https://tech-community.robotics.abb.com/t/raise-and-error-from-trap-routine/10675/2 "2022-04-05T13:45:00Z")

</div>

The error which has occurred might not be what you expect it to be. I recommend changing from IF THEN to a TEST CASE. Include a default and stop the program execution. Then you can view the value stored in the system ERRNO and compare it to find the actual error at that time.

---

<div class="post-metadata">

**Author:** ![enriquetracker](https://avatars.discourse-cdn.com/v4/letter/e/ce73a5/32.png) [@enriquetracker](https://tech-community.robotics.abb.com/u/enriquetracker)\
**Post date:** [April 5, 2022, 2:00pm UTC](https://tech-community.robotics.abb.com/t/raise-and-error-from-trap-routine/10675/3 "2022-04-05T14:00:43Z")

</div>

> [@lemster68](#):
>
> The error which has occurred might not be what you expect it to be. I recommend changing from IF THEN to a TEST CASE. Include a default and stop the program execution. Then you can view the value stored in the system ERRNO and compare it to find the actual error at that time.

Okey, would you give me an example? I am new here. THX!!!

---

<div class="post-metadata">

**Author:** ![lemster68](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/lemster68/32/1945_2.png) [@lemster68](https://tech-community.robotics.abb.com/u/lemster68)\
**Post date:** [April 5, 2022, 3:17pm UTC](https://tech-community.robotics.abb.com/t/raise-and-error-from-trap-routine/10675/4 "2022-04-05T15:17:09Z")

</div>

Here is one:

```auto
ERROR
    TEST ERRNO
    CASE erNumFault:
      TPWrite astNumFault{1};
      TPWrite "The program number received was: "\Num:=nProgramNumber;
      TPReadFK nDummy,"Press EXIT to exit:","","","","Exit","";
      EXIT;
    DEFAULT:
      TPErase;
      TPReadFK nDummy,"Handshaking was unsuccessful. Press EXIT to exit:","","","","Exit","";
      EXIT;
    ENDTEST

```

I often put a placeholder for an instruction in the default . This will cause an execution error, which WILL bring attention to the pendant. At this point one would view the ERRNUM datatype, find the value in ERRNO, and then find the corresponding predefined errors to find that which matches. Then you will know exactly what the error was. I highly recommend doing it this way because there are times when an error that you NEVER anticipated has occurred.
