[C++-sig] How to turn C++ error codes into Python exceptions?

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Mon Mar 27 19:10:38 CEST 2006


--- Matthias Baas <baas at ira.uka.de> wrote:
> But as there are a lot of functions that have to be wrapped that way I'm 
> wondering if there is some more automated solution. Would it be possible 
> to write custom call policy objects that do the above tests 
> automatically whenever a function has an argument of type MStatus*?

I've solved problems like this with simple Python scripts generating the C++
code with the Boost.Python bindings (e.g. http://cci.lbl.gov/gltbx/). Note that
I'm not using gcc-xml to maximize portability. If you are using pyste or py++
already I'd try to solve your problem by customizing the general-purpose code
generator.

> In the other case that a function returns a status object, would it be 
> possible to apply a custom to_python converter that actually does not 
> convert the result but perform an error check and throw an exception if 
> an error has occurred?

Sounds like a good idea. I'd give it a try.

Cheers,
        Ralf


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Cplusplus-sig mailing list