Re: Exceptions in gtkmm



On Thu, 2008-07-10 at 10:28 -0700, Sohail Somani wrote:
> Hey guys,
> 
> I'm trying to figure out the policy on exceptions in gtkmm. I notice 
> that, Gtk::Pixbuf throws an exception if you give it a file that doesn't 
> exist. I presume it converts some sort of error code to an exception.

Yes, we generally throw an exception when wrapping a C function that has
a GError output parameter. 

> What if one of my slots throws an exception?

It shouldn't, because this can't be passed back through a C function
that called your slot. See
http://www.gtkmm.org/docs/gtkmm-2.4/docs/FAQ/html/index.html#id2552300

>  Is there a way to catch all 
> such possible exceptions in one place so that I can report to the user?
> 
> The FAQ seems to say no but I'd *really* like this to not be true.

OK, so you've read that already. There's really no way for a C library
to use C++ exceptions unless you build that the library with a C
compiler. That is unlikely to be a possible solution unless you have a
very weird custom platform.

But really, you should catch exceptions quite early anyway. It's rarely
useful to you, or to a user, to just catch them in a main(), for
instance, because you can't recover or react sensibly, because you are
so far away from where the problem happened.

>  I do 
> understand the difficulties in throwing an exception in C++ called from 
> C code.
> 
> If you have any suggestions as to how I may achieve the equivalent 
> functionality if it doesn't exist, I'd be very happy with that.
> 
> Thanks.
> 
-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com




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