[C++-sig] How to handle argument error exceptions in boost.python?

Giuseppe Corbelli giuseppe.corbelli at copanitalia.com
Tue Jan 14 09:04:14 CET 2014


On 10/01/2014 14:16, Gary Oberbrunner wrote:
> [I posted this on StackOverflow yesterday, but got nothing.  Hoping you will have some insight!]
>
>
> I'm writing a C++ python extension.  I have a boost::python extension function
>
> static void EXTrender_effect(EffectGlobals_t *effect_handle,
>                      std::string preset,
>              bp::object dest, int xdim, int ydim)
> { ... }
> that I export as usual in my boost.python extension:
>
> def("render_effect", EXTrender_effect);
>
> When I call that from python(2.7), I get a C++ exception
> boost::python::error_already_set. Tracing that down in Visual Studio, I can
> see it's coming from a boost::python::objects::function::argument_error. So
> OK, I have an argument error; I'm probably calling it with the wrong args.
> What I'd like to do is print or throw something sensible in my python
> extension when this happens, so users of my extension will see the nice
> message that I know is lurking in PyErr_Fetch. (I can see the message getting
> built in the boost.python argument_error code.)

What is the exception you see from the python side? something like:

ArgumentError: Python argument types in
     function_name(function_args)
did not match C++ signature:
     cpp_function_name(cpp_args)

-- 
             Giuseppe Corbelli
WASP Software Engineer, Copan Italia S.p.A
Phone: +390303666318  Fax: +390302659932
E-mail: giuseppe.corbelli at copanitalia.com


More information about the Cplusplus-sig mailing list