If you override the Python sys.excepthook, it doesn't seem to get called on uncaught exceptions in Maya.
This is because it is not possible to override sys.excepthook directly as Maya already does that internally. However, since Maya 2011, there is a solution which will allow you to add your own exception hook. To perform an action when an exception occurs without modifying Maya's default printing of exceptions, do the following:
import maya.utils def myExceptCB(etype, value, tb, detail=2): # do something here... print "do something here..." return maya.utils._formatGuiException(etype, value, tb, detail) maya.utils.formatGuiException = myExceptCB
For older Maya releases, you would have to hack the file 'python.py' in the Maya installation. There is a function 'formatException' that you could change to do something when an exception happens.
Comments
You can follow this conversation by subscribing to the comment feed for this post.