aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/matplotlib/py2/src/py_exceptions.h
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2025-05-14 00:51:55 +0000
committerAlexander Smirnov <alex@ydb.tech>2025-05-14 00:51:55 +0000
commitb2d03716ee053cd32dccb8dd189d0b4bc3540d90 (patch)
treed329b3f92d5f80b8a76cac17d9e30bd1c8dc4b06 /contrib/python/matplotlib/py2/src/py_exceptions.h
parent645c59acc8ced6d89eb8559e26a7405d42ae9fb4 (diff)
parent0bf9db6399352012396e7791bcfd762e944b33c2 (diff)
downloadydb-b2d03716ee053cd32dccb8dd189d0b4bc3540d90.tar.gz
Merge branch 'rightlib' into merge-libs-250514-0050
Diffstat (limited to 'contrib/python/matplotlib/py2/src/py_exceptions.h')
-rw-r--r--contrib/python/matplotlib/py2/src/py_exceptions.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/contrib/python/matplotlib/py2/src/py_exceptions.h b/contrib/python/matplotlib/py2/src/py_exceptions.h
new file mode 100644
index 00000000000..1ee2d51903c
--- /dev/null
+++ b/contrib/python/matplotlib/py2/src/py_exceptions.h
@@ -0,0 +1,72 @@
+/* -*- mode: c++; c-basic-offset: 4 -*- */
+
+#ifndef __PY_EXCEPTIONS_H__
+#define __PY_EXCEPTIONS_H__
+
+#include <exception>
+#include <stdexcept>
+
+namespace py
+{
+class exception : public std::exception
+{
+ public:
+ const char *what() const throw()
+ {
+ return "python error has been set";
+ }
+};
+}
+
+#define CALL_CPP_FULL(name, a, cleanup, errorcode) \
+ try \
+ { \
+ a; \
+ } \
+ catch (const py::exception &) \
+ { \
+ { \
+ cleanup; \
+ } \
+ return (errorcode); \
+ } \
+ catch (const std::bad_alloc &) \
+ { \
+ PyErr_Format(PyExc_MemoryError, "In %s: Out of memory", (name)); \
+ { \
+ cleanup; \
+ } \
+ return (errorcode); \
+ } \
+ catch (const std::overflow_error &e) \
+ { \
+ PyErr_Format(PyExc_OverflowError, "In %s: %s", (name), e.what()); \
+ { \
+ cleanup; \
+ } \
+ return (errorcode); \
+ } \
+ catch (const std::runtime_error &e) \
+ { \
+ PyErr_Format(PyExc_RuntimeError, "In %s: %s", (name), e.what()); \
+ { \
+ cleanup; \
+ } \
+ return (errorcode); \
+ } \
+ catch (...) \
+ { \
+ PyErr_Format(PyExc_RuntimeError, "Unknown exception in %s", (name)); \
+ { \
+ cleanup; \
+ } \
+ return (errorcode); \
+ }
+
+#define CALL_CPP_CLEANUP(name, a, cleanup) CALL_CPP_FULL(name, a, cleanup, NULL)
+
+#define CALL_CPP(name, a) CALL_CPP_FULL(name, a, , NULL)
+
+#define CALL_CPP_INIT(name, a) CALL_CPP_FULL(name, a, , -1)
+
+#endif