Catching maya's error message

Catching maya's error message

viru.gupta8
Enthusiast Enthusiast
1,420 Views
2 Replies
Message 1 of 3

Catching maya's error message

viru.gupta8
Enthusiast
Enthusiast

hello,

i have a code where i am using try and except
ex:
try:
    do_something()
except:
    cmds.warning("some error")
 
this function may give some error ex: "pCube03 not found", "can't constraint pCube02"
how can we catch that error message and use that in except as warning.
0 Likes
Accepted solutions (1)
1,421 Views
2 Replies
Replies (2)
Message 2 of 3

RFlannery1
Collaborator
Collaborator
Accepted solution

Try this:

try:
    do_something()
except Exception as e:
    cmds.warning(str(e))

If that doesn't give the message you want, you can also try replacing the last line with:

cmds.warning(e.message)

0 Likes
Message 3 of 3

Anonymous
Not applicable

You may not get it directly, but you can get it indirectly

 

# Begin recording the Script Editor history to a file called
# tempHistoryLog.txt in your maya directory.
cmds.scriptEditorInfo( historyFilename='D:/tempHistoryLog.txt', writeHistory=True )

 

When it is turned on, it will always get information 

 

you can find  maya help

# Suppress all warning and info messages
cmds.scriptEditorInfo(suppressWarnings=True)
cmds.scriptEditorInfo(suppressInfo=True)
maybe can help you~~

 

0 Likes