Exceptions in gtkmm

View: New views
3 Messages — Rating Filter:   Alert me  

Exceptions in gtkmm

by Sohail Somani-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.

What if one of my slots throws an exception? 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. 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.

--
Sohail Somani
http://uint32t.blogspot.com

_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: Exceptions in gtkmm

by Murray Cumming :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
www.murrayc.com
www.openismus.com


_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Re: Exceptions in gtkmm

by Sohail Somani-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Murray,

Thanks for your response.

Murray Cumming wrote:

> 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

Sigh, yes I know :-(

Ok how about this: Is there a simple way to wrap each slot so that it is
effectively:

try
{
    call_real_slot();
}
catch(type1)
{..}
catch(type2)
{..}

I think it should be possible if I use a wrapper around sigc::slot. What
do you think?

All I really care about is being able to report the unhandled exceptions
to the user and/or logging them.

Thanks

--
Sohail Somani
http://uint32t.blogspot.com
_______________________________________________
gtkmm-list mailing list
gtkmm-list@...
http://mail.gnome.org/mailman/listinfo/gtkmm-list
LightInTheBox - Buy quality products at wholesale price