+ improve exception handling in initialization scripts

This commit is contained in:
wmayer 2015-12-29 23:42:29 +01:00
parent 9f4dc4616c
commit e9e9a38865
3 changed files with 18 additions and 5 deletions

View File

@ -36,7 +36,7 @@ import FreeCAD
def InitApplications(): def InitApplications():
try: try:
import sys,os import sys,os,traceback,cStringIO
except ImportError: except ImportError:
FreeCAD.PrintError("\n\nSeems the python standard libs are not installed, bailing out!\n\n") FreeCAD.PrintError("\n\nSeems the python standard libs are not installed, bailing out!\n\n")
raise raise
@ -96,7 +96,12 @@ def InitApplications():
exec open(InstallFile).read() exec open(InstallFile).read()
except Exception, inst: except Exception, inst:
Log('Init: Initializing ' + Dir + '... failed\n') Log('Init: Initializing ' + Dir + '... failed\n')
Err('During initialization the error ' + str(inst) + ' occurred in ' + InstallFile + '\n') Log('-'*100+'\n')
output=cStringIO.StringIO()
traceback.print_exc(file=output)
Log(output.getvalue())
Log('-'*100+'\n')
Err('During initialization the error ' + str(inst).decode('ascii','replace') + ' occurred in ' + InstallFile + '\n')
else: else:
Log('Init: Initializing ' + Dir + '... done\n') Log('Init: Initializing ' + Dir + '... done\n')
else: else:

View File

@ -159,7 +159,10 @@ std::string InterpreterSingleton::runString(const char *sCmd)
presult = PyRun_String(sCmd, Py_file_input, dict, dict); /* eval direct */ presult = PyRun_String(sCmd, Py_file_input, dict, dict); /* eval direct */
if (!presult) { if (!presult) {
throw PyException(); if (PyErr_ExceptionMatches(PyExc_SystemExit))
throw SystemExitException();
else
throw PyException();
} }
PyObject* repr = PyObject_Repr(presult); PyObject* repr = PyObject_Repr(presult);

View File

@ -98,7 +98,7 @@ class NoneWorkbench ( Workbench ):
return "Gui::NoneWorkbench" return "Gui::NoneWorkbench"
def InitApplications(): def InitApplications():
import sys,os import sys,os,traceback,cStringIO
# Searching modules dirs +++++++++++++++++++++++++++++++++++++++++++++++++++ # Searching modules dirs +++++++++++++++++++++++++++++++++++++++++++++++++++
# (additional module paths are already cached) # (additional module paths are already cached)
ModDirs = FreeCAD.__path__ ModDirs = FreeCAD.__path__
@ -113,7 +113,12 @@ def InitApplications():
exec open(InstallFile).read() exec open(InstallFile).read()
except Exception, inst: except Exception, inst:
Log('Init: Initializing ' + Dir + '... failed\n') Log('Init: Initializing ' + Dir + '... failed\n')
Err('During initialization the error ' + str(inst) + ' occurred in ' + InstallFile + '\n') Log('-'*100+'\n')
output=cStringIO.StringIO()
traceback.print_exc(file=output)
Log(output.getvalue())
Log('-'*100+'\n')
Err('During initialization the error ' + str(inst).decode('ascii','replace') + ' occurred in ' + InstallFile + '\n')
else: else:
Log('Init: Initializing ' + Dir + '... done\n') Log('Init: Initializing ' + Dir + '... done\n')
else: else: