Re: Exceptions in glib



Havoc Pennington <hp redhat com> writes:

> Most library functions just call g_malloc() and die on out-of-memory,
> because having an error just for that is too inconvenient; users of
> the library would always just ignore the error anyway. They already
> usually ignore real errors, such as parse errors and stuff.

We're using GTK in an embedded system, where memory is limited, and
allocation can always fail. I agree that checking every return value
is way too inconvenient, that's the reason exceptions look so
tempting for solving the problem.

How about a callback-based exception mechanism? Why not let the user
decide how to respond to an out-of-memory situation? That would also
decrease the problems of non-local exits (I would still use them in
the handler if appropriate).

> g_try_malloc() is intended for use where you are allocating a really
> large chunk of memory, and thus might expect failure, and also expect
> recovery to be possible. gdk_pixbuf_new() is a good example.

We expect failure all of the time, and most of the time we know how to
recover (kill mozilla, for instance :)).

Andreas





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]