Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: register_exception is not global on MacOS #5501

Closed
3 tasks done
gentlegiantJGC opened this issue Jan 24, 2025 · 1 comment
Closed
3 tasks done

[BUG]: register_exception is not global on MacOS #5501

gentlegiantJGC opened this issue Jan 24, 2025 · 1 comment
Labels
triage New bug, unverified

Comments

@gentlegiantJGC
Copy link
Contributor

gentlegiantJGC commented Jan 24, 2025

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

2.13.6

Problem description

On MacOS a C++ exception registered with py::register_exception will not be caught as the desired exception when raised from extension modules other than the one it was defined in.

In the following example I would expect a.throw_MyRuntimeError_a and b.throw_MyRuntimeError_b to raise a.MyRuntimeError.

This is the behaviour found on Windows and Linux but on MacOS b.throw_MyRuntimeError_b only raises python's RuntimeError. a.throw_MyRuntimeError_a works as expected.

Here is a pull request with tests on a repository with all the code required to reproduce this.
gentlegiantJGC/pybind11-crash#1

Reproducible example code

// my_runtime_error.hpp
#pragma once

#include <stdexcept>

class MyRuntimeError : public std::runtime_error {
public:
    using std::runtime_error::runtime_error;
};
// a.cpp
#include <pybind11/pybind11.h>

namespace py = pybind11;

#include "my_runtime_error.hpp"

PYBIND11_MODULE(a, m)
{
    py::register_exception<MyRuntimeError>(m, "MyRuntimeError", PyExc_RuntimeError);
    m.def("throw_MyRuntimeError_a", [](){ throw MyRuntimeError("MyRuntimeError_a"); });
}
// b.cpp
#include <pybind11/pybind11.h>

namespace py = pybind11;

#include "my_runtime_error.hpp"

PYBIND11_MODULE(b, m)
{
    m.def("throw_MyRuntimeError_b", [](){ throw MyRuntimeError("MyRuntimeError_b"); });
}

Is this a regression? Put the last known working version here if it is.

Unknown

@gentlegiantJGC gentlegiantJGC added the triage New bug, unverified label Jan 24, 2025
@gentlegiantJGC
Copy link
Contributor Author

Upon further investigation this is a duplicate of #2847

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New bug, unverified
Projects
None yet
Development

No branches or pull requests

1 participant