Not able to catch exception from builtin keywords

I want to create my own keyword, which can deal with few unexpected situations.
Example: Click an element, if other element would receive the click, wait a second and try again. throws StepFailedException.


public class WebUIOverride {
	public static void click(TestObject to) {
		try {
		} catch (StepFailedException ex) {
			KeywordUtil.logInfo("StepFailedException caught.")
			if(ex.getMessage().contains("Other element would receive the click")) {
				KeywordUtil.markWarning("Other element would receive the click. Trying again after 1 second...")
			} else {
				KeywordUtil.markFailed("Exception caught: " + ex)

Even if the StepFailedException occurs, it is not caught at custom keyword level. First error seems to be caught in this class:

ERROR c.k.k.core.keyword.internal.KeywordMain ❌ Unable to click on object 'Object Repository/xxx' (Root cause: org.openqa.selenium.WebDriverException: unknown error: Element \<img xxxyyy> is not clickable at point (2519, 136). Other element would receive the click:...

Later, StepFailedException appears, but it is never caught.

ERROR c.k.katalon.core.main.TestCaseExecutor ❌"xxx")) FAILED. Reason: com.kms.katalon.core.exception.StepFailedException: Unable to click on object 'Object Repository/xxx' (Root cause: the same as above)

How to handle such a situation? I tried to catch even Throwable class, but with no success.

1 Like, FailureHandling) has internal logic to handle exception. It handles the exception according to the 2nd argument: FailureHandling. So the caller script would never catch the StepFailedException.

You can read the source of at
You will find that uses org.openqa.selenium.WebElement#click(). You can mimic it. For example,

import org.openqa.selenium.WebElement
class ... {
    public static void click(TestObject to) {
        try {
            WebElement webElement = WebUIAbstractKeyword.findWebElement(to)
       } catch (Exceptio ex) {

I know, I am working on a workaround using pure WebDriver’s methods,
but I am wondering why there’s “…throws StepFailedException” statement in method’s documentation.
I wouldn’t mention it at all to prevent confusion.

1 Like

@Marek_Melocik mmhm … let me guess …
The StepFailedException is thrown by the keyword?
And you are trying to catch it in a custom keyword …

If you really need to catch that specific error type, you have to do it in the test-case.
Otherwise follow the @kazurayam workaround or you may have to use meta-programming to override the method

LE: i cannot find any API docs for com.kms.katalon.core.exception so, the above is just a blind guess …

Well, that was my initial approach - should throw StepFailedException.


But as @kazurayam said, it is consumed somewhere else.
Actually, using click() on WebElement solved the problem. Exception can be caught and handled as I need.

1 Like

This is where I suppose it is consumed, from the log you provided.
Looks like indeed it is raised using the Keyword annotation, but not catch-able in that scope …

LLE: the only place I found reference to this exception is in the BuiltInKeywords class, which is just using it and throwing to the above scope …