TRY EXCEPT in Keywords

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)

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

1 Like

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

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

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

Thanks

1 Like