diff --git a/src/python/axis.cpp b/src/python/axis.cpp index 7d35dd78..f4412eef 100644 --- a/src/python/axis.cpp +++ b/src/python/axis.cpp @@ -24,6 +24,7 @@ namespace np = boost::python::numpy; #include #include #include +#include namespace bp = boost::python; namespace bh = boost::histogram; @@ -152,18 +153,14 @@ template bp::str axis_get_label(const T& t) { } template bp::object axis_getitem(const A &a, int i) { - if (i < -1 * a.uoflow() || i >= a.size() + 1 * a.uoflow()) { - PyErr_SetString(PyExc_IndexError, "index out of bounds"); - bp::throw_error_already_set(); - } + if (i < -1 * a.uoflow() || i >= a.size() + 1 * a.uoflow()) + throw std::out_of_range("index out of bounds"); return bp::make_tuple(a.lower(i), a.lower(i+1)); } template <> bp::object axis_getitem>(const bha::category<> &a, int i) { - if (i < 0 || i >= a.size()) { - PyErr_SetString(PyExc_IndexError, "index out of bounds"); - bp::throw_error_already_set(); - } + if (i < 0 || i >= a.size()) + throw std::out_of_range("index out of bounds"); return bp::object(a.value(i)); } diff --git a/src/python/histogram.cpp b/src/python/histogram.cpp index dc529754..5761cd12 100644 --- a/src/python/histogram.cpp +++ b/src/python/histogram.cpp @@ -142,10 +142,8 @@ struct axes_appender { bp::object histogram_axis(const pyhistogram &self, int i) { if (i < 0) i += self.dim(); - if (i < 0 || i >= int(self.dim())) { - PyErr_SetString(PyExc_IndexError, "axis index out of range"); - bp::throw_error_already_set(); - } + if (i < 0 || i >= int(self.dim())) + throw std::out_of_range("axis index out of range"); return boost::apply_visitor(axis_visitor(), self.axis(i)); }