gerror: Document advantages of GError over numeric error codes

Despite knowing about GError, there are multiple cases where developers
have still used traditional numeric error codes, and then got themselves
into a mess about bindability and generation of error messages.

Try and avoid this by including a brief paragraph on the benefits of
GError over EINVAL-style error codes.

https://bugzilla.gnome.org/show_bug.cgi?id=743011
This commit is contained in:
Philip Withnall 2015-01-16 08:38:56 +00:00
parent 5ceaeef832
commit 04662a8667

View File

@ -51,6 +51,12 @@
* be eliminated by fixing the bug in the program. This is why most
* functions in GLib and GTK+ do not use the #GError facility.
*
* #GError has several advantages over numeric error codes: importantly, tools
* like [gobject-introspection](https://developer.gnome.org/gi/stable/)
* understand #GErrors and convert them to exceptions in bindings; the message
* includes more information than just a code; and use of a domain helps prevent
* misinterpretation of error codes.
*
* Functions that can fail take a return location for a #GError as their
* last argument. On error, a new #GError instance will be allocated and
* returned to the caller via this argument. For example: