ICON Community Interface 0.4.0
Loading...
Searching...
No Matches
exception.h
Go to the documentation of this file.
1#ifndef EXCPEPTION_H
2#define EXCPEPTION_H
3
4#include <memory>
5#include <stdexcept>
6#include <string>
7
8#define PY_SSIZE_T_CLEAN
9#include <Python.h>
10#include <comin.h>
11
12extern PyObject* PyExc_ComInError;
13
14class ComInError : public std::runtime_error {
15 std::string _what;
16
17 static std::string format_message(t_comin_error_code error_code,
18 std::string add_info) {
19 char category[11];
20 char message[COMIN_MAX_LEN_ERR_MESSAGE];
21 comin_error_get_message(error_code, category, message);
22 return std::string(category) + ": " + std::string(message) + "\n" +
23 add_info;
24 }
25
26public:
27 ComInError(t_comin_error_code error_code, std::string add_info)
28 : std::runtime_error(format_message(error_code, add_info)) {}
29};
30
31void py_comin_check_error(std::string add_info = "");
32
33template <PyCFunction Fun>
34PyObject* py_comin_func_wrapper(PyObject* self, PyObject* args) {
35 try {
36 return Fun(self, args);
37 } catch (ComInError& e) {
38 return PyErr_Format(PyExc_ComInError, e.what());
39 }
40}
41
42template <PyCFunctionWithKeywords Fun>
43PyObject* py_comin_func_wrapper(PyObject* self, PyObject* args,
44 PyObject* kwargs) {
45 try {
46 return Fun(self, args, kwargs);
47 } catch (ComInError& e) {
48 return PyErr_Format(PyExc_ComInError, e.what());
49 }
50}
51
52#endif
ComInError(t_comin_error_code error_code, std::string add_info)
Definition exception.h:27
C interface for the ICON Community Interface.
PyObject * PyExc_ComInError
PyObject * py_comin_func_wrapper(PyObject *self, PyObject *args)
Definition exception.h:34
void py_comin_check_error(std::string add_info="")