Re: [gtkmm] OT: C++ exceptions
- From: Jarek Dukat <madmaxer poczta fm>
- To: Gtkmm <gtkmm-list gnome org>
- Subject: Re: [gtkmm] OT: C++ exceptions
- Date: 08 Jul 2002 18:23:36 +0200
On Sun, 2002-07-07 at 22:14, Robert J. Hansen wrote:
> JD> --- G++ 3.1 (dla 2.95 tak samo):
> JD> Foo CTOR: 1
> JD> Foo CTOR: 2
> JD> UNEXPECTED!
> JD> Aborted
>
> JD> And according to my knowledge about C++ exceptions a correct result
> JD> should be:
> JD> Foo CTOR: 1
> JD> Foo CTOR: 2
> JD> UNEXPECTED!
> JD> Foo DTOR: 1
> JD> Ex2 caught
>
> JD> Obviously VC ignores unexpected() handler, and G++ treats it much too
> JD> seriously :)
> JD> What do you think about it?
>
> GCC 3.1 is correct. According to spec, a destructor must only be
> invoked for a fully-formed object. By throwing an exception in your
> constructor, you keep the first object from being fully formed; thus,
> no dtor gets invoked when it goes out of scope.
Yes, you're right about foo2. But foo1 hasn't been destroyed and this is
a bug, I think... It has been succesfully constructed, so it should be
cleaned up.
> Insofar as why foo(1)'s dtor isn't called... when you call foo(2), an
> exception gets thrown. Due to the fact foo(2) isn't declared to throw
> Ex2, foo(2)'s exception doesn't get caught in the try block--it
> automagically gets handled by the unexpected handler, which in turn
> re-throws a generic exception. The thread of execution then returns
> back to main(), which has catch() blocks for Ex1 and Ex2, but nothing
> for a generic exception.
>
> Does this help at all?
throw; should re-throw an exception of exactly the same type that
occoured before, so I think it should be handled by catch() in main().
I'm not sure but I've read something about special behaviour of
unexpected() handler in such case. But I may be wrong. Unfortunatelly I
don't have Stroustrup handy :)
Hmmm...
--
struct Sig {
string name(" J a r e k D u k a t ");
string mail(" madmaxer (at) poczta (dot) fm ");
};
-----------------------------------------------------------------------
2 lata za strzelanie do podobizny Balcerowicza?
>>> http://link.interia.pl/f1607
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]