Can I use the FailureHandling option by itself without attaching it an event

I want to fail the testcase for the following condition. I am able to run it, but the testcase is not failing right away. The test goes on to the next step. Please help with scenario so I can fail the testcase and the rest of the code does not run. TIA.

WebDriver driver = DriverFactory.getWebDriver()
String ErrorMsg = driver.findElement(By.className(‘text-danger’)).text
if (ErrorMsg == “”) {
//testcase passed
}
else {
//testcase failed
FailureHandling.STOP_ON_FAILURE
}

hi,

check this chain

Use this:

https://docs.katalon.com/katalon-studio/docs/force-stop-execution.html

Thanks @Timo_Kuisma1 and @Russ_Thomas

Used StepErrorException and it worked!