# How to print custom message in failure handling

**URL:** <https://forum.katalon.com/t/how-to-print-custom-message-in-failure-handling/6790>\
**Category:** Miscellaneous\
**Created:** [October 11, 2017, 1:36pm UTC](https://forum.katalon.com/t/how-to-print-custom-message-in-failure-handling/6790 "2017-10-11T13:36:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pk1](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@pk1](https://forum.katalon.com/u/pk1)\
**Post date:** [October 11, 2017, 1:36pm UTC](https://forum.katalon.com/t/how-to-print-custom-message-in-failure-handling/6790/1 "2017-10-11T13:36:05Z")

</div>

I have a line of code including “FailureHandling.STOP\_ON\_FAILURE” if that statement fails i want to print some message [note: only in case of step fails]  
How to achieve this.

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [October 11, 2017, 1:50pm UTC](https://forum.katalon.com/t/how-to-print-custom-message-in-failure-handling/6790/2 "2017-10-11T13:50:45Z")

</div>

Use rather FailureHandling.OPTIONAL and add to a next line:  
`KeywordUtil.markFailedAndStop("yourCustomMsg")`

It’ll fail a test with a custom message in next step, you can’t add a message to STOP\_ON\_FAILURE option.

---

<div class="post-metadata">

**Author:** ![pk1](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@pk1](https://forum.katalon.com/u/pk1)\
**Post date:** [October 11, 2017, 2:16pm UTC](https://forum.katalon.com/t/how-to-print-custom-message-in-failure-handling/6790/3 "2017-10-11T14:16:15Z")

</div>

WebUI.click(findTestObject(‘abc/button\_next’), FailureHandling.OPTIONAL)

//if above statement fails then the this message will print  
KeywordUtil.markFailedAndStop(" Next button does not click on abc page)

but markFailedAndStop statement is always executing even upper statement is true. HI just need to print message only when upper statement doesn’t execute. CAN YOU PLEASE HELP IN THIS. THANKS

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [October 12, 2017, 6:55am UTC](https://forum.katalon.com/t/how-to-print-custom-message-in-failure-handling/6790/4 "2017-10-12T06:55:43Z")

</div>

You have to wrap markFailed method in condition block. Then, it’ll be executed only when element is not present/clickable

```
if(!WebUI.verifyElementClickable(findTestObject('abc/button_next'), FailureHandling.OPTIONAL)) {
KeywordUtil.markFailedAndStop(" Next button does not click on abc page")
}
```

---

<div class="post-metadata">

**Author:** ![pk1](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@pk1](https://forum.katalon.com/u/pk1)\
**Post date:** [October 12, 2017, 2:16pm UTC](https://forum.katalon.com/t/how-to-print-custom-message-in-failure-handling/6790/5 "2017-10-12T14:16:57Z")

</div>

Thanks once gain Melocik. I also derived another way from your hint. Which is very much similar to your work.

if(WebUI.verifyElementClickable(findTestObject(‘abc/button\_next1’), FailureHandling.OPTIONAL))  
{  
WebUI.click(findTestObject(‘abc/button\_next’), FailureHandling.OPTIONAL)  
log.logInfo(" abc " + PageName[i])

```
	}
	else
	{
		KeywordUtil.markFailedAndStop(" abc " + PageName[i])
	}
```
