forked from JeanSebTr/node-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.cc
More file actions
43 lines (36 loc) · 1.12 KB
/
Copy pathutils.cc
File metadata and controls
43 lines (36 loc) · 1.12 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <Python.h>
#include <pyerrors.h>
#include "utils.h"
Handle<Value> ThrowPythonException() {
PyObject *ptype, *pvalue, *ptraceback;
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
// maybe useless to protect against bad use of ThrowPythonException ?
if(!ptype) {
return ThrowException(
Exception::Error(String::New("No exception found"))
);
}
// handle exception message
Local<String> msg;
if(pvalue && PyObject_TypeCheck(pvalue, &PyString_Type)) {
msg = String::New(PyString_AsString(pvalue));
}
Local<Value> err;
if(PyErr_GivenExceptionMatches(ptype, PyExc_ReferenceError)) {
err = Exception::ReferenceError(msg);
}
else if(PyErr_GivenExceptionMatches(ptype, PyExc_SyntaxError)) {
err = Exception::SyntaxError(msg);
}
else if(PyErr_GivenExceptionMatches(ptype, PyExc_TypeError)) {
err = Exception::TypeError(msg);
}
else {
err = Exception::Error(msg);
}
// @TODO : handle stacktrace
Py_XDECREF(ptype);
Py_XDECREF(pvalue);
Py_XDECREF(ptraceback);
return ThrowException(err);
}