aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/matplotlib/py3/src/py_exceptions.h
diff options
context:
space:
mode:
authorzverevgeny <zverevgeny@yandex-team.com>2025-05-13 19:00:02 +0300
committerzverevgeny <zverevgeny@yandex-team.com>2025-05-13 19:13:54 +0300
commit92e06374736aa28637dc0e706455b65c8268a5e6 (patch)
tree3df370c199ae25d308e542f02af20f43eab78f8a /contrib/python/matplotlib/py3/src/py_exceptions.h
parentdc63d5794da99c2ebe3f32914d0351d9707660b0 (diff)
downloadydb-92e06374736aa28637dc0e706455b65c8268a5e6.tar.gz
Import matplotlib
commit_hash:d59c2338025ef8fd1e1f961ed9d8d5fd52d0bd96
Diffstat (limited to 'contrib/python/matplotlib/py3/src/py_exceptions.h')
-rw-r--r--contrib/python/matplotlib/py3/src/py_exceptions.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/contrib/python/matplotlib/py3/src/py_exceptions.h b/contrib/python/matplotlib/py3/src/py_exceptions.h
new file mode 100644
index 00000000000..c4accf26340
--- /dev/null
+++ b/contrib/python/matplotlib/py3/src/py_exceptions.h
@@ -0,0 +1,72 @@
+/* -*- mode: c++; c-basic-offset: 4 -*- */
+
+#ifndef MPL_PY_EXCEPTIONS_H
+#define MPL_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, 0)
+
+#define CALL_CPP(name, a) CALL_CPP_FULL(name, a, , 0)
+
+#define CALL_CPP_INIT(name, a) CALL_CPP_FULL(name, a, , -1)
+
+#endif