- Where Developers Learn, Share, & Build Careers
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 Ex (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
Post a Comment