Commit 5ae60b33 authored by Tom Niget's avatar Tom Niget

Add error handler for python exceptions

parent 963a622d
......@@ -60,6 +60,7 @@ class ModuleVisitor(BlockVisitor):
yield ") {"
yield "InterpGuard guard{};"
yield "try {"
yield f"return py::module_::import(\"{mod}\").attr(\"{name}\")("
for i, argty in enumerate(fty.parameters):
if i != 0:
......@@ -68,6 +69,10 @@ class ModuleVisitor(BlockVisitor):
yield ").cast<"
yield from self.visit(fty.return_type)
yield ">();"
yield "} catch (py::error_already_set& e) {"
yield 'std::cerr << "Python exception: " << e.what() << std::endl;'
yield "throw;"
yield "}"
yield "}"
yield f"}} {alias};"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment