Get Exception handling working with Python 3

The old way to get the full stacktrace was incorrect, and does not work
with Python 3:
https://stackoverflow.com/questions/3702675/how-to-print-the-full-traceback-without-halting-the-program#comment84297600_33723119
This commit is contained in:
Thomas Pointhuber 2018-08-05 11:28:57 +02:00 committed by Maciej Suminski
parent 88d04f3bcb
commit 7365cb8e52
2 changed files with 10 additions and 4 deletions

View File

@ -447,7 +447,15 @@ wxString PyErrStringWithTraceback()
PyErr_Fetch( &type, &value, &traceback ); PyErr_Fetch( &type, &value, &traceback );
PyErr_NormalizeException( &type, &value, &traceback);
if (traceback == NULL) {
traceback = Py_None;
Py_INCREF( traceback );
}
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
PyException_SetTraceback(value, traceback);
PyObject* tracebackModuleString = PyUnicode_FromString( "traceback" ); PyObject* tracebackModuleString = PyUnicode_FromString( "traceback" );
#else #else
PyObject* tracebackModuleString = PyString_FromString( "traceback" ); PyObject* tracebackModuleString = PyString_FromString( "traceback" );

View File

@ -121,8 +121,7 @@ def LoadOnePlugin(Dirname, ModuleName):
if NOT_LOADED_WIZARDS != "" : if NOT_LOADED_WIZARDS != "" :
NOT_LOADED_WIZARDS += "\n" NOT_LOADED_WIZARDS += "\n"
NOT_LOADED_WIZARDS += module_filename NOT_LOADED_WIZARDS += module_filename
FULL_BACK_TRACE += traceback.format_exc(sys.exc_info()) FULL_BACK_TRACE += traceback.format_exc()
pass
@ -154,8 +153,7 @@ def LoadOneSubdirPlugin(Dirname, SubDirname):
if NOT_LOADED_WIZARDS != "" : if NOT_LOADED_WIZARDS != "" :
NOT_LOADED_WIZARDS += "\n" NOT_LOADED_WIZARDS += "\n"
NOT_LOADED_WIZARDS += fullPath NOT_LOADED_WIZARDS += fullPath
FULL_BACK_TRACE += traceback.format_exc(sys.exc_info()) FULL_BACK_TRACE += traceback.format_exc()
pass
else: else:
if NOT_LOADED_WIZARDS != "" : if NOT_LOADED_WIZARDS != "" :