Re: Exceptions in glib
- From: Owen Taylor <otaylor redhat com>
- To: Andreas Bogk <andreas andreas org>
- Cc: gtk-devel-list gtk org
- Subject: Re: Exceptions in glib
- Date: 07 Feb 2001 11:06:27 -0500
Andreas Bogk <andreas andreas org> writes:
> I was discussing the problem of error handling in GTK with my
> colleagues, and ended up suggesting the use of an exception
> Here's my first implementation of this, I would like to hear your
> opinions on whether that's a good thing to do in GTK or not:
The suggestion to add setjmp/longjmp exceptions has come up a lot.
The answer we've always arrived at is no.
- It's not portable.
- It's not safe if you have code in between that isn't expecting it
- It's not safe with any language beside C.
Etc. The error handling mechanism we've introduced for GLib-2.0
is just a simple extra-parameter:
GError *err = NULL;
if (!g_file_get_contents (filename, &str, NULL, &err))
if (g_error_matches (err, G_FILE_ERROR, G_FILE_ERROR_NOENT))
g_print ("File doesn't exist!\n");
g_print ("File could not be read: %s\n", err->message);
] [Thread Prev