# C++ exception handler
if func_type.exception_check == '+':
if func_type.exception_value is None:
- env.use_utility_code(cpp_exception_utility_code)
+ env.use_utility_code(UtilityCode.load_cached("CppExceptionConversion", "CppSupport.cpp"))
def calculate_result_code(self):
return self.c_call_code()
#------------------------------------------------------------------------------------
-cpp_exception_utility_code = UtilityCode(
-proto = """
-#ifndef __Pyx_CppExn2PyErr
-#include <new>
-#include <typeinfo>
-#include <stdexcept>
-#include <iostream>
-
-static void __Pyx_CppExn2PyErr() {
- // Catch a handful of different errors here and turn them into the
- // equivalent Python errors.
- try {
- if (PyErr_Occurred())
- ; // let the latest Python exn pass through and ignore the current one
- else
- throw;
- } catch (const std::bad_alloc& exn) {
- PyErr_SetString(PyExc_MemoryError, exn.what());
- } catch (const std::bad_cast& exn) {
- PyErr_SetString(PyExc_TypeError, exn.what());
- } catch (const std::domain_error& exn) {
- PyErr_SetString(PyExc_ValueError, exn.what());
- } catch (const std::invalid_argument& exn) {
- PyErr_SetString(PyExc_ValueError, exn.what());
- } catch (const std::ios_base::failure& exn) {
- // Unfortunately, in standard C++ we have no way of distinguishing EOF
- // from other errors here; be careful with the exception mask
- PyErr_SetString(PyExc_IOError, exn.what());
- } catch (const std::out_of_range& exn) {
- // Change out_of_range to IndexError
- PyErr_SetString(PyExc_IndexError, exn.what());
- } catch (const std::overflow_error& exn) {
- PyErr_SetString(PyExc_OverflowError, exn.what());
- } catch (const std::range_error& exn) {
- PyErr_SetString(PyExc_ArithmeticError, exn.what());
- } catch (const std::underflow_error& exn) {
- PyErr_SetString(PyExc_ArithmeticError, exn.what());
- } catch (const std::exception& exn) {
- PyErr_SetString(PyExc_RuntimeError, exn.what());
- }
- catch (...)
- {
- PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
- }
-}
-#endif
-""")
-
pyerr_occurred_withgil_utility_code= UtilityCode(
proto = """
static CYTHON_INLINE int __Pyx_ErrOccurredWithGIL(void); /* proto */
--- /dev/null
+/////////////// CppExceptionConversion.proto ///////////////
+
+#ifndef __Pyx_CppExn2PyErr
+#include <new>
+#include <typeinfo>
+#include <stdexcept>
+#include <iostream>
+
+static void __Pyx_CppExn2PyErr() {
+ // Catch a handful of different errors here and turn them into the
+ // equivalent Python errors.
+ try {
+ if (PyErr_Occurred())
+ ; // let the latest Python exn pass through and ignore the current one
+ else
+ throw;
+ } catch (const std::bad_alloc& exn) {
+ PyErr_SetString(PyExc_MemoryError, exn.what());
+ } catch (const std::bad_cast& exn) {
+ PyErr_SetString(PyExc_TypeError, exn.what());
+ } catch (const std::domain_error& exn) {
+ PyErr_SetString(PyExc_ValueError, exn.what());
+ } catch (const std::invalid_argument& exn) {
+ PyErr_SetString(PyExc_ValueError, exn.what());
+ } catch (const std::ios_base::failure& exn) {
+ // Unfortunately, in standard C++ we have no way of distinguishing EOF
+ // from other errors here; be careful with the exception mask
+ PyErr_SetString(PyExc_IOError, exn.what());
+ } catch (const std::out_of_range& exn) {
+ // Change out_of_range to IndexError
+ PyErr_SetString(PyExc_IndexError, exn.what());
+ } catch (const std::overflow_error& exn) {
+ PyErr_SetString(PyExc_OverflowError, exn.what());
+ } catch (const std::range_error& exn) {
+ PyErr_SetString(PyExc_ArithmeticError, exn.what());
+ } catch (const std::underflow_error& exn) {
+ PyErr_SetString(PyExc_ArithmeticError, exn.what());
+ } catch (const std::exception& exn) {
+ PyErr_SetString(PyExc_RuntimeError, exn.what());
+ }
+ catch (...)
+ {
+ PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
+ }
+}
+#endif