From 2b9fdbe7c9f989506fef6eb04159587d86b3a73d Mon Sep 17 00:00:00 2001 From: Jonas Adler Date: Tue, 15 Dec 2015 11:27:19 +0100 Subject: [PATCH] ENH: add more error conversions --- include/pybind11/pybind11.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index e0b1064bf..eb0bf206a 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -294,10 +294,16 @@ private: if (result != (PyObject *) 1) break; } - } catch (const error_already_set &) { return nullptr; - } catch (const index_error &e) { PyErr_SetString(PyExc_IndexError, e.what()); return nullptr; - } catch (const stop_iteration &e) { PyErr_SetString(PyExc_StopIteration, e.what()); return nullptr; - } catch (const std::exception &e) { PyErr_SetString(PyExc_RuntimeError, e.what()); return nullptr; + } catch (const error_already_set &) { return nullptr; + } catch (const index_error &e) { PyErr_SetString(PyExc_IndexError, e.what()); return nullptr; + } catch (const stop_iteration &e) { PyErr_SetString(PyExc_StopIteration, e.what()); return nullptr; + } catch (const std::bad_alloc &e) { PyErr_SetString(PyExc_MemoryError, e.what()); return nullptr; + } catch (const std::domain_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return nullptr; + } catch (const std::invalid_argument &e) { PyErr_SetString(PyExc_ValueError, e.what()); return nullptr; + } catch (const std::length_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return nullptr; + } catch (const std::out_of_range &e) { PyErr_SetString(PyExc_IndexError, e.what()); return nullptr; + } catch (const std::range_error &e) { PyErr_SetString(PyExc_ValueError, e.what()); return nullptr; + } catch (const std::exception &e) { PyErr_SetString(PyExc_RuntimeError, e.what()); return nullptr; } catch (...) { PyErr_SetString(PyExc_RuntimeError, "Caught an unknown exception!"); return nullptr;