catching python exceptions from _hou module

   6563   4   2
User Avatar
Member
5 posts
Joined: March 2011
Offline
It seems as if something prevents catching exceptions generated from the _hou plugin. It's nice to at least see the traceback, but I would rather be able to generate that myself and to be able to catch the exceptions for handling more gracefully in my code. What's this about? Is there some special mode that I need to be in to be able to catch the exceptions?

e.g.,
The line that is throwing the exception is encapsulated in a try/except block.

Traceback (most recent call last):
File “<console>”, line 1, in <module>
File “<console>”, line 170, in otlImport
File “<console>”, line 12, in relockParents
File “/home/prisms/builder-new/Nightly11.0/dev/hfs/houdini/python2.5libs/hou.py”, line 5146, in matchCurrentDefinitio
n
return _hou.Node_matchCurrentDefinition(*args)
OperationFailed: The attempted operation failed.
User Avatar
Member
1908 posts
Joined: Nov. 2006
Online
It should work just like catching any other Python exception. Can you post more of your code (maybe the entire try/except block) to see exactly what might be causing the problem?

>>> try:
hou.node('/obj/subnet1/inilne_pycode').matchCurrentDefinition()
except hou.OperationFailed:
print “Oops, I failed.”

Oops, I failed.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
5 posts
Joined: March 2011
Offline
try:
node.matchCurrentDefinition()
if isLockedAsset(node):
if DEBUG: print “now locked again”
else:
if DEBUG: print “failed to lock previously locked node %s” % path
except Exception, e:
print(“relockParents failed with exception %s %s on %s” % (e, str(e), path))

This is not the first or only time that I have encountered this from the _hou plugin. I have only been doing python code in houdini for the last week, but have done a lot of other python programming. But I have seen this a number of times where something fails in the plugin but the try/except doesn't catch it. We are on 11.0.692.
User Avatar
Member
1908 posts
Joined: Nov. 2006
Online
Your problem is that you are trying to catch an Exception, whereas Houdini is throwing a hou.OperationFailed exception. In HOM, the base exception is hou.Error, not any built-in Python exceptions so that is why it is not being caught. If your code is going to be throwing a Houdini exception then you should try to catch hou.Error.

For example, something like a ValueError is a subclass of the regular Exception, however hou.Error is not, so will never be caught when trying to catch Exception.
>>> issubclass(ValueError, Exception)
True
>>> issubclass(hou.Error, Exception)
False
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
2 posts
Joined: July 2016
Offline
What exception would be raised during a hou.hipFile.load(<hipfile>)

It's getting hung up on errors found in the Python Source Editor code.

In my particular situation, I'm instantiating a Qt widget inside of my Python Source Editor. When I open the hip file using hython, it fails with a non-zero exit because it doesn't know how to handle the gui that's spawning on load.

I'm trying to catch that Exception
try:
    hou.hipFile.load(hip_file)
except:
    print "skipping failed py src editor code"
Edited by Tuckz - July 7, 2016 18:18:09
  • Quick Links