[PyKDE] Handling exceptions in SIP
Denis S. Otkidach
ods at strana.ru
Thu Jun 30 10:25:21 BST 2005
On Wed, 29 Jun 2005 15:59:08 +0100
Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> > sip command passes without error, but I have an error when linking:
> > $OFILES in Makefile contains sipMyModuleMyException.o, while there is no
> > corresponding .cpp file generated.
> >
> > BTW, when I use throw specifier in method signature without
> > corresponding %Exception directive, sip exits with non-zero code, but
> > reports no error message.
> >
> > All tests were done with sip-snapshot-20050626.
>
> Should be fixed in tonight's snapshot.
Simple examples work like a charm with sip-snapshot-20050629, thanks!
There are some points to discuss:
1) If sipExceptionRef is not used in RaiseCode we'll get a warning.
2) Exceptions that were not specified in throw are not caught and I see
no way to add "catch(...)" to generated code.
3) throw specifier has no effect on generated code when %MethodCode is
used, shouldn't it?
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
--
Denis S. Otkidach
http://www.python.ru/ [ru]
More information about the PyQt
mailing list