How to stop calculating the mouseClicked event?

I have a button with some script. I used it to get the data from database when the mouseclicked event is fired. But before getting the data, I have to check some condition in that script. And I have to stop that script from calculating if that condition doesn’t meet. I used the sys.exit() but I got the error. I want to stop that script like exit sub or exit function in VB. Is there a way to do it?

sys.exit will do the trick. What is the error you are getting? Are you importing sys?

Yes. I’m importing sys. But as far as I know, sys.exit will pop up a message box when I use it. The problem is I want to stop the script but I don’t want to get the pop up message. :scratch:

Here is an example that works for me:[code]import sys
text = event.source.parent.getComponent(‘Text Field’).text

if text == “”:
sys.exit()

print “here”[/code]

Yes. It works for me too. But it’s not what I mean. The problem is I got an error when I run that script. And I don’t want that error message to be appeared. I just wanted to stop the script. I want to know that how to stop the script from running without that error message appears. I took the screenshot and attached it here.

Oh ok, well wrap the code in a try except like this:try: your code except: passThat might get rid of the error message.

Thanks. It works. :smiley: :smiley: