Repository navigation
Expand file tree
/
Copy pathexceptions.cpp
More file actions
55 lines (50 loc) · 1.42 KB
/
Copy pathexceptions.cpp
File metadata and controls
55 lines (50 loc) · 1.42 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
44
45
46
47
48
49
50
51
52
53
54
55
#include "exceptions.h"
#include "defines.h"
#include <sstream>
static PyObject* IcsArgumentError = NULL;
static PyObject* IcsRuntimeError = NULL;
int initialize_exceptions(PyObject* module)
{
if (!module && IcsArgumentError && IcsRuntimeError) {
return 0;
}
// ArgumentError
IcsArgumentError = PyErr_NewException(MODULE_NAME ".ArgumentError", NULL, NULL);
if (!IcsArgumentError) {
return 0;
}
Py_INCREF(IcsArgumentError);
PyModule_AddObject(module, "ArgumentError", IcsArgumentError);
// RuntimeError
IcsRuntimeError = PyErr_NewException(MODULE_NAME ".RuntimeError", NULL, NULL);
if (!IcsRuntimeError) {
return 0;
}
Py_INCREF(IcsRuntimeError);
PyModule_AddObject(module, "RuntimeError", IcsRuntimeError);
return 1;
}
PyObject* _set_ics_exception(PyObject* exception, const char* msg, const char* func_name)
{
std::stringstream ss;
std::string function = std::string(func_name);
auto loc = function.find("meth_");
if (loc != std::string::npos) {
function.erase(loc, 5);
}
ss << "Error: " << function << "(): " << msg;
if (!exception) {
PyErr_SetString(PyExc_Exception, ss.str().c_str());
} else {
PyErr_SetString(exception, ss.str().c_str());
}
return NULL;
}
PyObject* exception_argument_error(void)
{
return IcsArgumentError;
}
PyObject* exception_runtime_error(void)
{
return IcsRuntimeError;
}