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:
> Hi!
>
> I was discussing the problem of error handling in GTK with my
> colleagues, and ended up suggesting the use of an exception
> mechanism.
>
> 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;
char *str;
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");
else
g_print ("File could not be read: %s\n", err->message);
g_clear_error (&err);
}
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]