E
eric
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
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