Handling errors inside BOOST_PYTHON_MODULE() #280
Description
Activity
What happens if you replace
std::exceptionbystd::runtime_erroror some other more specific exception type ?No, switching to
std::runtime_errordoes not help, I still haveunreported exception. And looks like the exception type has nothing to do with the issue: I set a debug breakpoint in
Lines 48 to 51 in ac62db1
catch(const std::exception& x) { PyErr_SetString(PyExc_RuntimeError, x.what()); }
and verified that this catch case was executed.OK, I see. So the Python error has correctly been set by Boost.Python, but Python's own runtime then flags this as an "unreported exception". In other words, you could strip your code off all Boost.Python references, only using Python's own C API, and you'd still observe the issue.
Can you report this to the Python bug tracker ?Are you sure that's a Python problem? Maybe
Line 24 in 1727b67
handle_exception(init_function);
should be replaced withif (handle_exception(init_function)) return NULL;
?
Reacted by Thomas DelameOh, indeed, that looks sensible. Can you write a (minimal) test case to demonstrate the problem as well as that your proposed change fixes it ? That would make a great PR !
I just tried to fix it locally this way and it solved the problem. Well, I could try to create a test case and PR, but I'm quite new to boost libs testing infrastructure...
OK, great. I'll see whether I can write a quick test.
Hi @stefanseefeld
Any news on the issue? Are you still planning to create a test and finally commit the fix?Had the same issue, boost::python was hiding the real exception with
raised unreported exception. I applied the patchif (handle_exception(init_function)) return NULL;mentioned by @db4 and now the real exception is thrown.Also just ran into this problem.. Just bumping this issue to show it's still relevant and affects users.
Also just ran into this problem.. Just bumping this issue to show it's still relevant and affects users.
I finally decided to stop waiting for something and create PR myself
Reacted by Thomas- added 2 commits that reference this issue
on Feb 8, 2021
I have a module that may fail to initialize due to missing dependencies. So I do
The exception is correctly caught and
PyErr_SetString(PyExc_RuntimeError, x.what())is called, but python reportsWhy
unreported exception? My platform is Windows 10/Python 3.7.4 x64/MSVC 2017 if that matters. python_boost version is 1.69.0.