Re: [gtkmm] gtk-- exceptions - was Re: Gtk-- FAQ: first draft available
- From: Karl Nelson <kenelson ece ucdavis edu>
- To: gtkmm modeemi cs tut fi
- cc: gtk-list redhat com, kenelson ece ucdavis edu
- Subject: Re: [gtkmm] gtk-- exceptions - was Re: Gtk-- FAQ: first draft available
- Date: Fri, 23 Jul 1999 11:00:21 -0700
In message <37989D1C.8210454C@ibmoto.com>Todd Dukes writes
>Karl Nelson wrote:
>>
>[...]
>> Should Gtk-- place a try/catch block arround the calls to the user
>> callbacks that catchs all to an error message or let it
>> crash GTK+ and hopefully fall through as an uncaught exception?
>>
>> Or alternatively can we write a gtk_signal_exception_cleanup
>> function that can clean up the mess?
>
>I would like to be able to use exceptions in as transparent a method
>as possible. But if that solution causes ugly code with bad
>performance, it should be avoided. I have the following questions.
Transparent would be to make this work
try {
button.pressed();
}
catch () {/*...*/}
work. However, I don't think that will happen.
>1. What would a gtk_signal_exception_cleanup function do? I am not
> sure I understand exactly what we need to fix, or what method
> is used to fix it.
Well, I assume that the user is saying that a signal path which
throws an exception back through a c function path will cause
problems. But I don't think that you can ever trust that it
won't seg fault immediately when it hits gtk+ code. If it
does work the user would have to call a clean up routine imediately
in the catch. Not a good idea. (Or gtk+ would have to be exception
aware, also not too good.)
>2. Where would it go (gtk-- code or user code)?
Depends on the solution. A try block in the emitter is
internal to gtk--, but then the user would have to supply
a catch function to gtk-- some how. (See Esa Pulkkinen's
page on reusing catch functions.)
>3. What would it do to the performance of programs that don't
> use exceptions?
Well, it takes about 1-5% off most programs to have the try blocks
that are not used. To verify how much it is on your compiler
use this code
----------------------------------------------------------------
#define TRY 1
int j;
void foo()
{ j++; }
main()
{
for (int i=0;i<(2<<24);i++)
{
#if TRY
try
{
#endif
foo();
#if TRY
}
catch (...) {}
#endif
}
}
----------------------------------------------------------------
On my machine....
without try: 4.570u 0.010s 0:04.57 100.2% 0+0k 0+0io 109pf+0w
with try: 4.820u 0.010s 0:04.82 100.2% 0+0k 0+0io 109pf+0w
5% penalty for try blocks, in a trivial program. (less in
larger programs)
--Karl
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]