« Return to Thread: Using %attribute and %exception together

Re: Using %attribute and %exception together

by wsfulton :: Rate this Message:

Reply to Author | View in Thread

  Geoffrey Philbrick wrote:

> I am wrapping my get/set methods with an attribute/member for Python as
> follows:
>
>  
>
> %attribute(MyObject, double, value, get, set)
>
>  
>
> Prior to using %attribute I was handling exceptions thrown from the C++
> MyObject::set like this:
>
>  
>
> %exception MyObject::set {
>
>    try {
>
>       $action
>
>    } catch (RangeException &e) {
>
>          PyErr_SetString(PyExc_ValueError, const_cast<char*>(e.what()));
>
>          return NULL;
>
>    }
>
> }
>
>  
>
> This works fine without %attribute, but no longer works because the set
> method is called through this macro, thus the code to handle the
> exception is never inserted:
>
>  
>
> MyObject_value_set(arg1,arg2);
>
>  
>
> What is the correct way to use these two constructs together?
>
>  
>

Did you know about %feature("exceptvar") ? This works like %exception,
but the exception handling code only gets applied to variable wrappers.
Also if you use %allowexception, %exception handling code will also
apply to variable wrappers, see the html documentation for this latter
feature.

William

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: Using %attribute and %exception together

LightInTheBox - Buy quality products at wholesale price