Error | Exception Handling

How can I handle an error or exception in Robort that is equivalent to Try Catch?

Wait Until Keyword Succeeds    3x    0.5 sec    do stuff

works, but it only does Retry instead of Error Handling.

I don’t just want it does Retry, I want handle error that is equivalent to Try Catch
or event Re-Throw* the exception.
Something like the Java style code:

try {
} catch (Exception ex) {

I might in a For Loop that I want ignore and skip the error when certain retry amount still fails,
or I might want log some info when it fails,
or I might proceed to different logic when it fails.

Please advice if it is possible the Robort can do try catch rethrow like so.

There are a couple of options. For proper try/except/finally, use Python (for the logic that requires that).

With Robot Framework syntax, you use the Teardown functionality (think it as finally) and maybe the internal ${TEST_STATUS} variable, described here:

Here’s the snippet from that thread:

*** Tasks ***
Main process
    Do something here
    Maybe this fails
    [Teardown]    Send mail on error

*** Keywords ***
Send mail on error
    IF    '${TEST_STATUS}' == 'FAIL'
        Send email    log.txt

Also see Robot Framework User Guide for more information about teardown.

In addition, there are many built-in keywords that can ignore errors and return the status of the operation. Then you can use that return status as your boolean for branching the logic.


Thanks! This is exactly what I want.
And I just use the Fail keyword to simulate the try catch throw exception.

1 Like