[pygtk] GError-Exception support and exception handling in GOption

Johannes Hölzl johannes.hoelzl at gmx.de
Fri May 26 02:37:20 WST 2006


Hi,

the gobject.option implementation of GOption currently doesn't handle
errors when for example an option gets the wrong argument (for example:
"--number=text"). 

To support exception in gobject.Option i implemented:

/**
 * Checks if a GError exception occurred in python and set the GError.
 * If the exception is not a GError or the GError exception has no
 * domain, code and message attributes the exception is printed.
 *
 * Ensures the GIL state.
 *
 * Returns: True if a python-exception was set and this exception was a 
 *          correct GError-Exception.
 */
gboolean
pyg_set_gerror_from_exception (GError **error_dest)

To use this function, the python-code must create a gobject.GError()
object and add domain, code and message attributes manually, for
example:

err = gobject.GError(message)
err.domain = gobject.OPTION_ERROR
err.code = gobject.OPTION_ERROR_BAD_VALUE
err.message = "Wrong option ..."
raise err

Or should i add a full GError-class? 

I didn't look, but are there other places in pygtk where a
GError-Exception isn't translated into GError?

The attached patch adds this function and the exception handling in
GOption.

best regards,
	Johannes Hölzl

PS: Are two patches, one with only pyg_set_gerror_from_exception
implementation and another with exception support in GOption preferred?

-------------- nächster Teil --------------
Ein Dateianhang mit Bin�rdaten wurde abgetrennt...
Dateiname   : goption-exceptionhandling.patch
Dateityp    : text/x-patch
Dateigr��e  : 12484 bytes
Beschreibung: 
URL         : http://www.daa.com.au/pipermail/pygtk/attachments/20060525/ed655246/goption-exceptionhandling-0001.bin


More information about the pygtk mailing list