Hello,
I created some job scripts recently and I have a few checks in place where a scriptDialog.ShowMessageBox(errorTitle, errorMessage) is displayed with some instructions when the user’s input is not what the script expects or if some files could be overwritten but I would like to add a generic message box displaying the stacktrace for any uncaught exception.
Especially, I would like to avoid the silent fail/nothing happens behavior after launching a job script that raises an exception.
If there is an error in my code, the stacktrace only appears in the Python console window. Which is fine for me, but is very confusing for actual users of the scripts who typically never have the console window open and, more importantly, are not notified that the script execution failed: The user right clicks on a job and chooses the script in the sub-menu but then nothing happens so they’re not sure why nothing happened or if maybe something happened in the background.
I tried overriding sys.excepthook with my own function as described here but this seems to be completely ignored by Deadline Monitor.
I also tried renaming my __main__()
function to mainExcept()
and using this for __main__()
instead:
def __main__():
try:
mainExcept()
except BaseException as e:
displayErrorDialog("Python execution error", e)
But this doesn’t work either.
- Is there another option to achieve my goal ?
I see that the following code (in C:\Program Files\Thinkbox\Deadline10\bin\UI\DeadlineUI\Commands\ScriptCommands.pyc) is responsible for writing the stacktrace to the console:
class BaseScriptQAction(DeadlineAction):
[...]
def InnerExecute(self):
try:
[...]
except:
Trace2.WriteLine(traceback.format_exc())
- Is there a way to hook a custom function into the
FranticX.Diagnostics.Trace2
class?
Ideally I would like to call my own function displayErrorDialog() whenever an exception is raised.