Re: [gtkmm] OT: C++ exceptions
- From: Spandan Bhatt <spandan_bhatt yahoo com>
- To: Jarek Dukat <madmaxer poczta fm>, Gtkmm <gtkmm-list gnome org>
- Subject: Re: [gtkmm] OT: C++ exceptions
- Date: Wed, 10 Jul 2002 20:31:17 -0700 (PDT)
Can somebody enlighten me?
How is unexpected exception thrown by this code?
what does
Foo(int _i) throw(Ex1);
mean?(does it always throw the exception? Even if it
does from the code I saw it looked like that exception
was suposed to be handled!! where is the unexpected
exception. I must be making some silly mistake..)
Spundun
--- Jarek Dukat <madmaxer poczta fm> wrote:
> This question is OT, but there are many C++ experts
> here so perhaps you
> could explain it. Please look at this sample code:
>
> // ---------------------------------------------
> #include <exception>
> #include <iostream>
> using namespace std;
>
> struct Ex1 {};
> struct Ex2 {};
>
> class Foo {
> int i;
> public:
> Foo(int _i) throw(Ex1);
> ~Foo();
> };
> Foo::Foo(int _i) throw(Ex1) : i(_i) {
> cerr << "Foo CTOR: " << i << endl;
> if ( i == 2 )
> throw Ex2();
> }
> Foo::~Foo() {
> cerr << "Foo DTOR: " << i << endl;
> }
>
> void my_unex() {
> cerr << "UNEXPECTED!" << endl;
> throw;
> }
>
> int main() {
> set_unexpected(my_unex);
> try {
> Foo foo1(1);
> Foo foo2(2);
> } catch ( Ex1& ) {
> cerr << "Ex1 caught" << endl;
> } catch ( Ex2& ) {
> cerr << "Ex2 caught" << endl;
> }
> return 0;
> }
> // ---------------------------------------------
>
> After compiling it with different compilers I get
> different! results!
>
> --- VC6:
> Foo CTOR: 1
> Foo CTOR: 2
> Foo DTOR: 1
> Ex2 caught
>
> --- G++ 3.1 (dla 2.95 tak samo):
> Foo CTOR: 1
> Foo CTOR: 2
> UNEXPECTED!
> Aborted
>
> And according to my knowledge about C++ exceptions a
> correct result
> should be:
> Foo CTOR: 1
> Foo CTOR: 2
> UNEXPECTED!
> Foo DTOR: 1
> Ex2 caught
>
> Obviously VC ignores unexpected() handler, and G++
> treats it much too
> seriously :)
> What do you think about it?
>
> --
> struct Sig {
> string name(" J a r e k D u k a t ");
> string mail(" madmaxer (at) poczta (dot) fm ");
> };
>
>
>
----------------------------------------------------------------------
> Wiesz, co zdarzylo sie dzisiaj? >>>
> http://link.interia.pl/f1605
>
>
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]