From: Nitro <ni...@dr...> - 2010-04-23 21:05:19
|
Am 23.04.2010, 23:48 Uhr, schrieb Bob Hood <bh...@co...>: > I'm causing a number of Swig::DirectorExceptions to be thrown while > developing my SWIG wrapper. The code that is raising these exceptions > all look something like: > > if (result == NULL) { > PyObject *error = PyErr_Occurred(); > if (error != NULL) { > Swig::DirectorMethodException::raise("Error detected when calling > '<director_method>'"); > } > } > > I can't seem to find a good "hook" point to trap these. My application > has a very high level trap for any exceptions that are thrown > ("catch(...)") which is, of course, capturing all these throws. > However, this is well outside of the SWIG-generated wrapper code, where > DirectorException is defined, so I can't simply add a case for it, e.g.: > > try > { > ... > } > catch (Swig::DirectorException e) > { > } > catch (...) > { > ... > } > > It'd likely be better if I could re-work that auto-generated > DirectorException code in the wrapper, but I am not seeing (in the docs) > a way to override it, nor a way to construct an "%exception" that will > target only these types of exceptions without having to specify one for > each and every Director method being wrapped. > > Would anybody have advice on a better way to capture these, or perhaps a > way to use my own code for the error check instead of letting it throw > the Swig::DirectorException? Can I somehow get the DirectException > defined in the SWIG runtime header (e.g., "swigpyrun.h") which would > then at least allow me to capture it at the application level? Does %feature("director:except") work for you? -Matthias |