Catch block not executed

I want to use catch block in case that some of tests fail so my code snippet is like below

try {
‘Wait username field to become visible’
WebUI.waitForElementVisible(findTestObject(‘Page_Login/input_loginComponentj_username’), GlobalVariable.timeout)

'Type username'
not_run: WebUI.sendKeys(findTestObject('Page_Login/input_loginComponentj_username'), GlobalVariable.ceoUsername.toString().concat(
        '##').concat(GlobalVariable.loginname))

'Type username'
WebUI.sendKeys(findTestObject('Page_Login/input_loginComponentj_username'), 'scosic##npalikuca')

'Type password'
WebUI.sendKeys(findTestObject('Object Repository/Page_ERP 3.0/input_Password_loginComponentj'), GlobalVariable.password)

'Click on Login button'
WebUI.click(findTestObject('Object Repository/Page_ERP 3.0/span_Login'))

'Wait home form to be visible'
WebUI.waitForElementVisible(findTestObject('Page_Home/HomeForm'), GlobalVariable.timeout, FailureHandling.CONTINUE_ON_FAILURE)

'Logout'
WebUI.click(findTestObject('Page_Login/span_Logout'), FailureHandling.CONTINUE_ON_FAILURE)
} catch (Exception e) {
println 'Exception caught ' + e.printStackTrace()
} 

Test fails within try block but catch block is not executed. Anyone has an idea what is wrong with my code?

What is the failure that occurs? If it’s a handled test failure (not a thrown exception), then your catch will have no effect.

Try this to see the difference:

import com.kms.katalon.core.exception.StepErrorException as StepErrorException


try {

  // your test steps here...

  throw new StepErrorException("I hate brussels sprouts")

  // More steps here...

} catch (Exception e) {
  printLn e.message
}

Thanks, it works! Exception is org.openqa.selenium.TimeoutException