forked from ModOrganizer2/modorganizer-plugin_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.cpp
More file actions
26 lines (23 loc) · 753 Bytes
/
error.cpp
File metadata and controls
26 lines (23 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef Q_MOC_RUN
#include <boost/python.hpp>
#endif
#include <QString>
#include <utility.h>
using namespace MOBase;
namespace bpy = boost::python;
void reportPythonError()
{
if (PyErr_Occurred()) {
// prints to s_ErrIO buffer
PyErr_Print();
// extract data from python buffer
bpy::object mainModule = bpy::import("__main__");
bpy::object mainNamespace = mainModule.attr("__dict__");
bpy::object errMsgObj = bpy::eval("s_ErrIO.getvalue()", mainNamespace);
QString errMsg = bpy::extract<QString>(errMsgObj.ptr());
bpy::eval("s_ErrIO.truncate(0)", mainNamespace);
throw MyException(errMsg);
} else {
throw MyException("An unexpected C++ exception was thrown in python code");
}
}