Error options in Sikuli?

Asked by arminius on 2017-07-10

Can Sikuli ignore errors and just move to the next line?
I have a loop, and 9 times out of 10 it works perfectly, everynow and then it throws an error, I would rather just tell it to move on, or return to the start of the loop or even more complex instructions.

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Manfred Hampl (m-hampl) said : #1

As already written in another question asked by you: You need to get better in python basics.

You might also do a web search for 'sikuli try except', there are already some answers to similar questions.

arminius (arminius75) said : #2

I've got Sololearn on my phone and Code academy on my desktop, improving my Python as fast as I can.
Besides the error is unique to Sikuli I think, findfailed is only a Sikuli error I assume?
I should have said if Findfails can anything be done? Returning to the top of the loop would be perfect.

Manfred Hampl (m-hampl) said : #3

You might need a construction like this

looping statement (for... or while... etc.):
        do-some-logic # it is there
    except FindFailed:
        pass # pattern not found, just ignore it and return to the loop

arminius (arminius75) said : #4

For newbs who came after me, I found this ""

ABORT – all subsequent find failed operations (explicit or implicit) will raise exception FindFailed (which is the default when a script is started).
SKIP – all subsequent find operations will not raise exception FindFailed. Instead, explicit find operations such as Region.find() will return None. Implicit find operations (action functions) such as will do nothing and return 0.
PROMPT – all subsequent find operations will not raise exception FindFailed. Instead you will be prompted for the way to handle the situation (see using PROMPT). Only the current find operation is affected by your response to the prompt.
RETRY – all subsequent find operations will not raise exception FindFailed. Instead, Sikuli will try to find the target until it gets visible. This is equivalent to using wait( ... , FOREVER) instead of find() or using setAutoWaitTimeout(FOREVER)."

Skip will probably do what I need, I'll have to test it later tonight.

Manfred Hampl (m-hampl) said : #5

As already written in question
If you are using Sikuli 1.1 and higher, the documentation is there

Your link points to the documentation for Sikuli 1.0 only.

Manfred Hampl (m-hampl) said : #7

Your link and my link are pointing to the same document, just to a position that is a few paragraphs (about 3 pages) different.

Generally I see two options for you:
1. turn off the feature that exceptions are raised when an image is not found (setFindFailedResponse)
2. use exception handling (try: ... except: ...) in those cases where you suspect that the image might be not present on the screen (but leave exception signaling enabled).