Python and C have quite different ways of reporting errors.
In Python exceptions are raised (and possibly
caught) whenever an error occurs.
In C a function will typically return an error value, such as
-1 or NULL.
To raise a Python exception you have to
check the return value when you call the function.
For example, the following modification of the
__new__
method we wrote earlier raises
SomeKindOfExcpetion if
xosd_create returns NULL.
def __new__(self, font, colour):
self.xosdWin = xosd_create(1)
if (self.xosdWin == NULL):
msg = 'xosd_create returned NULL'
raise SomeKindOfException(msg)
xosd_set_font(self.xosdWin, font)
xosd_set_colour(self.xosdWin, colour)