Customized Error Messages / Hide Code in Error Message

Asked by Jeff Sant

Dear Friends,

Whenever there is an error on my code, the error box shows the code which has problem, it also shows variable names, or image names.

Is there any way i can prevent this?

Thanks

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

-- you say: the error box shows
are you talking about the popup, that comes up at exceptions, when running a script from command line?
this can be suppressed (redirected to the command line's stout using the parameter -s

-- Generally:
you have to use try: except: to catch exceptions and handle your own messaging (e.g. to a file) in the except: branch.
mor info: http://jythonpodcast.hostjava.net/jythonbook/chapter6.html#chapter-6-exception-handling-and-debugging

Revision history for this message
Jeff Sant (sant-jeff) said :
#2

Dear Friend,

Thanks for your answer.

Can i have try and catch for the complete program, i mean the try should start with the beginning and at the end the program should have catch, so if anything happens anywhere it should show error message

In VB we use msgbox err.description to show what error happened, how can i do it in sikuli, or i have to give it a customized message?

Thanks

Revision history for this message
RaiMan (raimund-hocke) said :
#3

--- you say: Can i have try and catch for the complete program, i mean the try should start with the beginning and at the end the program should have catch, so if anything happens anywhere it should show error message

yes, you can do that.

-- you say: In VB we use msgbox err.description to show what error happened, how can i do it in sikuli, or i have to give it a customized message?

using:
try:
    # here comes your code
except:
    print sys.exc_info()[0], sys.exc_info()[1]

would print out the error information. So use sys.exc_info() as you like (e.g. with popup())

Revision history for this message
Jeff Sant (sant-jeff) said :
#4

Dear Friend,

This works perfect, is there any way that error can show the line number of the error?

Thanks

Revision history for this message
RaiMan (raimund-hocke) said :
#5

Can you help with this problem?

Provide an answer of your own, or ask Jeff Sant for more information if necessary.

To post a message you must log in.