# TRY EXCEPT in Keywords

**URL:** <https://forum.robotframework.org/t/try-except-in-keywords/6559>\
**Category:** Robot Framework\
**Created:** [14 December 2023 10:20 UTC](https://forum.robotframework.org/t/try-except-in-keywords/6559 "2023-12-14T10:20:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![camilb](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@camilb](https://forum.robotframework.org/u/camilb)\
**Post date:** [14 December 2023 10:20 UTC](https://forum.robotframework.org/t/try-except-in-keywords/6559/1 "2023-12-14T10:20:16Z")

</div>

Hi All,

i get this error:  
Multiple errors:

- TRY structure must have EXCEPT or FINALLY branch.
- TRY must have closing END.

Looks pretty clear but i do have TRY EXCEPT and END in my code but it’s in the Keywords section not in Test Case section.

TRY  
Should Be Equal As Strings “${enter\_password}” “Enter Password\n”  
EXCEPT  
Close Websocket  
Fatal Error “Enter Password not found”  
END

So what im doing wrong? why do i get the errors?  
Im using:  
Robot Framework 6.0.2 (Python 3.10.12 on linux)

---

<div class="post-metadata">

**Author:** ![Silken](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Silken](https://forum.robotframework.org/u/Silken)\
**Post date:** [14 December 2023 20:35 UTC](https://forum.robotframework.org/t/try-except-in-keywords/6559/2 "2023-12-14T20:35:24Z")

</div>

Could you post your code sample in a blockquote? That way we can see if there is an indentation issue.

Ex. This code would give you that error because EXCEPT isn’t properly indented.

> ```
> TRY
> Should Be Equal As Strings “${enter_password}” “Enter Password\n”
> 
> ```
> 
> EXCEPT  
> Close Websocket  
> Fatal Error “Enter Password not found”  
> END

---

<div class="post-metadata">

**Author:** ![camilb](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@camilb](https://forum.robotframework.org/u/camilb)\
**Post date:** [19 January 2024 14:34 UTC](https://forum.robotframework.org/t/try-except-in-keywords/6559/3 "2024-01-19T14:34:01Z")

</div>

Hi Silken,

sure here’s my code which is in the _ **Task** _ Section

```
TRY
    Open UEFI Boot And Enter BIOS Password
EXCEPT
	Close Websocket From PiKVM
	Fatal Error "Enter Password not found"
END
Select UEFI Image To Boot And Start Provisioning
TRY
    Check provisioning is running
EXCEPT
    Close Websocket From PiKVM
    Fatal Error "Error in check provisioning"
END

```

This is working - but if i try to use TRY EXECPT END in the _ **Keywords** _ Section then somehow it gives me the error i mentiont.

I will try again.

Br,  
Camil

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [19 January 2024 15:00 UTC](https://forum.robotframework.org/t/try-except-in-keywords/6559/4 "2024-01-19T15:00:58Z")

</div>

Hi camilb

Could you provide the actual \*\*\* Tasks \*\*\* / \*\*\* Keyword \*\*\* section with the task or keyword and try/catch in where you are having the problem or ensure it is formatted with the correct indentation? It should look similar in formatting to this basic example:

![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/2/28bd9594439478d5db90302add40110fd6d23592.png)

the same format will be consistent wherever you put the Try/Catch whether in a Task/Test/Keyword

Thanks
