unexpected exception

Discussion in 'C++' started by Teddy, May 25, 2005.

  1. Teddy

    Teddy Guest

    Hello all

    According to "Think in C++ Volume2", the code below should run
    smoothly:
    #include <iostream>
    #include <exception>
    using namespace std;

    class ex {
    };

    void func() throw(ex) {
    throw 10;
    }

    void my_unexpected() {
    cout << "unexpected exception" << endl; // this never shows up on my
    VC compilers
    exit(0);
    }

    int main()
    {
    set_unexpected(my_unexpected);

    try {
    func();
    }
    catch(ex) {
    cout << "ex caught" << endl;
    }

    return 0;
    }


    But on my VC2003 and VC2005 BETA2, there will be a compiling warning
    and a runtime error.
    VC doesn't support unexpected exception ?
    or something else ?
     
    Teddy, May 25, 2005
    #1
    1. Advertising

  2. Teddy wrote:
    > Hello all
    >
    > According to "Think in C++ Volume2", the code below should run
    > smoothly:
    > #include <iostream>
    > #include <exception>
    > using namespace std;
    >
    > class ex {
    > };
    >
    > void func() throw(ex) {
    > throw 10;
    > }
    >
    > void my_unexpected() {
    > cout << "unexpected exception" << endl; // this never shows up on my
    > VC compilers
    > exit(0);
    > }
    >
    > int main()
    > {
    > set_unexpected(my_unexpected);
    >
    > try {
    > func();
    > }
    > catch(ex) {
    > cout << "ex caught" << endl;
    > }
    >
    > return 0;
    > }
    >
    >
    > But on my VC2003 and VC2005 BETA2, there will be a compiling warning
    > and a runtime error.
    > VC doesn't support unexpected exception ?
    > or something else ?
    >


    The code works fine for me (SuSE Linux Pro v9.2,
    g++ v3.3.4). It produces the expected output:

    "unexpected exception"

    So it must be a VC problem. Try checking
    with a VC-specific forum.

    Regards,
    Larry


    --
    Anti-spam address, change each 'X' to '.' to reply directly.
     
    Larry I Smith, May 25, 2005
    #2
    1. Advertising

  3. Teddy

    Raymond Guest

    Hello Teddy:

    I have compile and run this program using MinGW g++.
    The result is "unexpected exception". So g++ support the unexpected
    exception.

    The following his the Version Information of my compiler.

    --------------------------------------------------------
    g++ (GCC) 3.4.2 (mingw-special)
    Copyright (C) 2004 Free Software Foundation, Inc.
    --------------------------------------------------------
     
    Raymond, May 25, 2005
    #3
  4. Teddy

    Razzer Guest

    Teddy wrote:
    > Hello all
    >
    > According to "Think in C++ Volume2", the code below should run
    > smoothly:
    > #include <iostream>
    > #include <exception>
    > using namespace std;
    >
    > class ex {
    > };
    >
    > void func() throw(ex) {
    > throw 10;
    > }
    >
    > void my_unexpected() {
    > cout << "unexpected exception" << endl; // this never shows up on my
    > VC compilers
    > exit(0);
    > }
    >
    > int main()
    > {
    > set_unexpected(my_unexpected);
    >
    > try {
    > func();
    > }
    > catch(ex) {
    > cout << "ex caught" << endl;
    > }
    >
    > return 0;
    > }
    >
    >
    > But on my VC2003 and VC2005 BETA2, there will be a compiling warning
    > and a runtime error.
    > VC doesn't support unexpected exception ?
    > or something else ?


    The Microsoft compilers ignore the exception specification that you
    specified on your function. It is a compiler limitiation, so you will
    not get the expected (conforming) results.
     
    Razzer, May 25, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nicolas edel
    Replies:
    5
    Views:
    3,062
    Gordon Beaton
    Jul 31, 2003
  2. James Ly
    Replies:
    3
    Views:
    704
    James
    Dec 3, 2003
  3. Replies:
    2
    Views:
    12,677
  4. R.A.M.
    Replies:
    4
    Views:
    9,899
    R.A.M.
    May 19, 2006
  5. RAM
    Replies:
    0
    Views:
    405
Loading...

Share This Page