heritaged exception features

Discussion in 'C++' started by eric, Jun 15, 2011.

  1. eric

    eric Guest

    Dear advanced c++ programers:

    I tried to copied and test a piece of (simple code) from page 823 of
    book (C++ Primer Plus-5th Ed by Stephen Prata). about heritaged
    exceptions features.

    --------------------------------------
    #include <iostream>

    using namespace std;

    class bad_1 {...};
    class bad_2 : public bad_1 {...};
    class bad_3 : public bad_2 {...};

    void duper() throw (bad_1) // matches base- and derived-class objects
    {
    int oh_no = 1,
    rats = 0,
    drat = 0;

    if (oh_no)
    throw bad_1();
    if (rats)
    throw bad_2();
    if (drat)
    throw bad_3();

    }

    int main() {
    try {
    duper();
    }

    catch(bad_3) {
    cout << "\ngoto bad_3\n";
    }

    catch(bad_2) {
    cout << "\ngoto bad_2\n";
    }

    catch(bad_1) {
    cout << "\ngoto bad_1\n";
    }

    }
    ----------------------------------------------
    but I got compile error:

    eric@eric-laptop:~/cpppp5/ch15$ g++ pg823.cpp
    pg823.cpp:5:14: error: expected unqualified-id before ‘...’ token
    pg823.cpp:6:29: error: expected unqualified-id before ‘...’ token
    pg823.cpp:7:29: error: expected unqualified-id before ‘...’ token

    plz help , see how to modify (or what kind (unqualified-id) I should
    add in somewhere in my simple test program)?
    thanks a lot in advance, Eric
    eric, Jun 15, 2011
    #1
    1. Advertising

  2. On 6/15/2011 3:12 PM, eric wrote:
    > I tried to copied and test a piece of (simple code) from page 823 of
    > book (C++ Primer Plus-5th Ed by Stephen Prata). about heritaged
    > exceptions features.
    >
    > --------------------------------------
    > #include<iostream>
    >
    > using namespace std;
    >
    > class bad_1 {...};
    > class bad_2 : public bad_1 {...};
    > class bad_3 : public bad_2 {...};


    Are those ellipses (sets of dots) in your source code *verbatim*? The
    example in the book simply didn't want to elaborate on the contents of
    those classes (likely), and you have to at least remove those.
    Otherwise, it's a simple syntax error. Change those three lines to read:

    class bad_1 {};
    class bad_2 : public bad_1 {};
    class bad_3 : public bad_2 {};

    >
    > void duper() throw (bad_1) // matches base- and derived-class objects
    > {
    > int oh_no = 1,
    > rats = 0,
    > drat = 0;
    >
    > if (oh_no)
    > throw bad_1();
    > if (rats)
    > throw bad_2();
    > if (drat)
    > throw bad_3();
    >
    > }
    >
    > int main() {
    > try {
    > duper();
    > }
    >
    > catch(bad_3) {
    > cout<< "\ngoto bad_3\n";
    > }
    >
    > catch(bad_2) {
    > cout<< "\ngoto bad_2\n";
    > }
    >
    > catch(bad_1) {
    > cout<< "\ngoto bad_1\n";
    > }
    >
    > }
    > ----------------------------------------------
    > but I got compile error:
    >
    > eric@eric-laptop:~/cpppp5/ch15$ g++ pg823.cpp
    > pg823.cpp:5:14: error: expected unqualified-id before ‘...’ token
    > pg823.cpp:6:29: error: expected unqualified-id before ‘...’ token
    > pg823.cpp:7:29: error: expected unqualified-id before ‘...’ token
    >
    > plz help , see how to modify (or what kind (unqualified-id) I should
    > add in somewhere in my simple test program)?
    > thanks a lot in advance, Eric


    V
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jun 15, 2011
    #2
    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. Ami Schreiber
    Replies:
    1
    Views:
    683
    Dino Chiesa [Microsoft]
    Nov 24, 2003
  2. Replies:
    0
    Views:
    553
  3. Abdelhalim

    VHDL features Usage statistics

    Abdelhalim, May 18, 2004, in forum: VHDL
    Replies:
    3
    Views:
    691
    Abdelhalim
    May 19, 2004
  4. Jonathan Mcdougall
    Replies:
    2
    Views:
    492
    Kaz Kylheku
    Nov 3, 2005
  5. BillJosephson
    Replies:
    148
    Views:
    2,642
    peter koch
    Jan 27, 2007
Loading...

Share This Page