GNOME Bugzilla – Bug 143018
Gtk::IconTheme::lookup_icon() should throw an exception if gtk_icon_theme_lookup_icon() returns NULL
Last modified: 2004-12-22 21:47:04 UTC
Gtk::IconTheme::lookup_icon wraps the gtk_icon_info pointer returned by gtk_icon_theme_lookup_icon(). The C function returns a NULL value for the pointer if the icon searched for cannot be found: accordingly a null Gtk::IconInfo object is returned where the C function fails. However, there is no Gtk::IconInfo::operator bool() function to test the validity of the Gtk::IconInfo object, and in any event it would be better to throw an exception, like Gtk::IconTheme::load_icon().
I would not like to add an exception where there is no corresponding GError in the C function. Well, maybe, but we need to be consistent about when we throw an error and when we return an invalid instance - just mapping GTK+ means we don't need to decide about that. So, adding operator bool() is probably the correct fix here. A patch would be welcome, as an API addition for a future gtkmm 2.5/2.6. As a workaround for now, you can check gobj() for 0. This bug might also be interesting: http://bugzilla.gnome.org/show_bug.cgi?id=143632
I can do a patch. Is an operator!() also required?
On reflection, if we have an operator bool(), then operator !() is not necessary. It would only be useful if we were to test the object with operator void*().
Yes, other gtkmm classes just have operator bool().
Done in HEAD. 2004-11-17 Murray Cumming <murrayc@murayc.com> * gtk/src/iconinfo.[hg|ccg]: Added operator bool(), needed to check the result of IconTheme::lookup_icon(). Bug #143018.