[PyKDE] Handling exceptions in SIP
Phil Thompson
phil at riverbankcomputing.co.uk
Fri Jul 1 17:37:44 BST 2005
On Friday 01 July 2005 7:55 am, Denis S. Otkidach wrote:
> On Thu, 30 Jun 2005 17:24:27 +0100
>
> Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> > > 4) There are several standard exceptions which I always have to catch.
> > > Now I have a macro for them:
> > >
> > > #define CATCH_STD_EXCEPTIONS \
> > > catch (std::bad_alloc&) {\
> > > PyErr_NoMemory(); \
> > > sipIsErr = 1; \
> > > } catch (std::exception &exc) {\
> > > PyErr_SetString(PyExc_RuntimeError, exc.what()); \
> > > sipIsErr = 1; \
> > > } catch (...) {\
> > > PyErr_SetString(PyExc_RuntimeError, "unknown"); \
> > > sipIsErr = 1; \
> > > }
> > >
> > > used in %MethodCode:
> > >
> > > %MethodCode
> > > try {
> > > sipRes = someMethod(...);
> > > } CATCH_STD_EXCEPTIONS // sipIsErr - this comment is important hint
> > > to SIP! %End
> >
> > If your point is the need for the comment, then yes - consider it a
> > feature.
>
> No, I meant these exceptions must be caught almost everywhere. So I
> have to add %MethodCode to almost every method, which is annoying. The
> latest release of SIP always catch all exceptions with "catch(...)"
> clause with -e option, but now it doesn't.
If we solve the problem of how to specify "..." then you could define
std::bad_alloc, std::exception, and (somehow) "..." using %Exception and
then...
void foo() throw (std::bad_alloc, std::exception, ...);
If this is too much trouble, then I can only suggest implementing something
like %DefaultExceptionHandler than contains your code and is applied to
anything that has no throw specifier (so long as the -e option is used).
Phil
More information about the PyQt
mailing list