c++ - boost::python export custom exception and inherit from Python's Exception -


Indicates how to export a custom exception class from C ++, and how the exception class is exported How can I do the exception of Python? It exposes an exception class that has custom methods for receiving the information and that category has been obtained with the exception of Python.

A practical solution, rather than receiving from the wrapped C ++ recommended by Jim Bosch, of the structure To use The code should be made to be a python exception as is done, and then add a C ++ exception wrapped as an example variable of the Python exception.

  Zero Translator (const MyCPPException & x) {BP :: Object AX (X); // C + Exception: BP :: Object exc_t Wrap (BP :: Handle : (BP :: Credit (exception type)); Exc_t.attr ("cause") = exc; // Python exception add wrapped exceptions PyErr_SetString (exceptionType, x.what ()); }  

Wrapped C ++ exception can be accessed from Python in such a way:

  Try: MyModule.MyCPPExceptionType e: Reason = E  

But the exception here will also be caught

  Try: ... except the exception: ...  

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -