File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed
Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -213,9 +213,28 @@ bool CPythonManager::Initialize( void )
213213 python::import (" __init__" ).attr (" load" )();
214214 }
215215 catch ( ... ) {
216- PyErr_Print ();
217- PyErr_Clear ();
218- Msg (MSG_PREFIX " Failed to load the main module.\n " );
216+ Msg (MSG_PREFIX " Failed to load the main module due to following exception:\n " );
217+
218+ // Don't use PyErr_Print() here because our sys.excepthook has not been installed
219+ // yet so let's just format and output to the console ourself.
220+ if (PyErr_Occurred ())
221+ {
222+ PyObject *pType;
223+ PyObject *pValue;
224+ PyObject *pTraceback;
225+ PyErr_Fetch (&pType, &pValue, &pTraceback);
226+ PyErr_NormalizeException (&pType, &pValue, &pTraceback);
227+
228+ handle<> hType (pType);
229+ handle<> hValue (allow_null (pValue));
230+ handle<> hTraceback (allow_null (pTraceback));
231+
232+ object format_exception = import (" traceback" ).attr (" format_exception" );
233+ Msg (extract<const char *>(str (" \n " ).join (format_exception (hType, hValue, hTraceback))));
234+
235+ PyErr_Clear ();
236+ }
237+
219238 return false ;
220239 }
221240
You can’t perform that action at this time.
0 commit comments