1/////////////// CppExceptionConversion.proto ///////////////
2
3#ifndef __Pyx_CppExn2PyErr
4#include <new>
5#include <typeinfo>
6#include <stdexcept>
7#include <ios>
8
9static void __Pyx_CppExn2PyErr() {
10  // Catch a handful of different errors here and turn them into the
11  // equivalent Python errors.
12  try {
13    if (PyErr_Occurred())
14      ; // let the latest Python exn pass through and ignore the current one
15    else
16      throw;
17  } catch (const std::bad_alloc& exn) {
18    PyErr_SetString(PyExc_MemoryError, exn.what());
19  } catch (const std::bad_cast& exn) {
20    PyErr_SetString(PyExc_TypeError, exn.what());
21  } catch (const std::domain_error& exn) {
22    PyErr_SetString(PyExc_ValueError, exn.what());
23  } catch (const std::invalid_argument& exn) {
24    PyErr_SetString(PyExc_ValueError, exn.what());
25  } catch (const std::ios_base::failure& exn) {
26    // Unfortunately, in standard C++ we have no way of distinguishing EOF
27    // from other errors here; be careful with the exception mask
28    PyErr_SetString(PyExc_IOError, exn.what());
29  } catch (const std::out_of_range& exn) {
30    // Change out_of_range to IndexError
31    PyErr_SetString(PyExc_IndexError, exn.what());
32  } catch (const std::overflow_error& exn) {
33    PyErr_SetString(PyExc_OverflowError, exn.what());
34  } catch (const std::range_error& exn) {
35    PyErr_SetString(PyExc_ArithmeticError, exn.what());
36  } catch (const std::underflow_error& exn) {
37    PyErr_SetString(PyExc_ArithmeticError, exn.what());
38  } catch (const std::exception& exn) {
39    PyErr_SetString(PyExc_RuntimeError, exn.what());
40  }
41  catch (...)
42  {
43    PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
44  }
45}
46#endif
47