This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Catching exceptions by reference
- To: gcc-help at gcc dot gnu dot org
- Subject: Catching exceptions by reference
- From: mattseeger at netscape dot net (Matthias Seeger)
- Date: Wed, 21 Mar 2001 11:26:39 -0500
Hello,
in Stroustrups 3rd edition (C++ programming language), p.360, he claims
that exceptions can be caught by reference (example below). This would
be very useful for exception class hierarchies.
class a {
public:
void f() {
cout << "A" << endl;
}
};
class b : public a {
public:
void f() {
cout << "B" << endl;
}
};
main()
{
try {
throw b();
} catch (a& ex) {
ex.f();
} catch (...) {
cout << "Caught s.th. else" << endl;
}
}
The output here is "A" instead of "B", as claimed by Stroustrup. Even
worse, if "catch (a& ex)" is replaced by "catch(a* ex)", the output is
"Caught s.th. else".
Is anything like catching exceptions by reference realized in GCC?
Thanks,
__________________________________________________________________
Get your own FREE, personal Netscape Webmail account today at http://webmail.netscape.com/