|
From: Barry S. <ba...@ba...> - 2016-05-25 19:31:37
|
If any of you have the time to look over the latest changes to PyCXX I would
appreciate any feedback.
I have added code to pycxx that allows exceptions raise in Python to be caught
in C++ using the Python exception name.
For example:
try
{
call-python
}
catch( ValueError &e )
{
// handle value error
}
catch( UserDefinedError &e )
{
// handle user defined error
}
See Demon/Python3/simple.cxx and simple.py for example code.
I have checked in the first pas of this code for python3 on trunk.
(I also created a pycxx-6.2-maint branch)
The way this works is to have a std::map (cxx_exceptions.cxx) that
contains a map from python type objects to a function that will raise the
C++ equivalent.
The fucntion ifPyErrorThrowCxxException is called everywhere pycxx code
is entered from python and an exception may have be raise. It will convert
into a C++ exception and throw it.
I think the code of SimpleError in simple.cxx is all boiler plate and I can
turn that into a macros. One to declare the other to init.
Barry
|