Replies: 1 comment
-
We ended up using this code snippet to throw Python APyFixed APyFixed::operator/(const APyFixed& rhs) const
{
if (rhs.is_zero()) {
PyErr_SetString(PyExc_ZeroDivisionError, "fixed-point division by zero");
throw nb::python_error();
}
...
} Please let me know if mixing calls to the Python C-API like this together with nanobind can cause any trouble for us. Then I'll consider this question answered. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
We are writing a fixed-point arithmetic library for Python, using nanobind, and we would like to raise a
ZeroDivisionError
from C++ on division-by-zero using our custom fixed-point types. Can this be achieved using nanobind? I've seenZeroDivisionError
mentioned in the nanobind documentation undervoid register_exception_translator()
:but I don't understand if this is used to raise exceptions from C++. I haven't seen
ZeroDivisionError
mentioned throughout the pybind11 documentation either.Can we raise the
ZeroDivisionError
from C++ using nanobind, and if so, how can we do this?Best regards,
Mikael
Beta Was this translation helpful? Give feedback.
All reactions