This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Catching exceptions by reference


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]