Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-08-21 09:55:00


Something I've been meaning to add to more/error_handling.html since
last fall was just added:

  Use virtual inheritance. This insight is due to Andrew Koenig. Using
  virtual inheritance from your exception's base class(es) prevents
  ambiguity problems at the catch-site in case someone throws an
  exception derived from multiple bases which have a base class in
  common:

  #include <iostream>
  struct my_exc1 : std::exception { char const* what() throw(); };
  struct my_exc2 : std::exception { char const* what() throw(); };
  struct your_exc3 : my_exc1, my_exc2 {};

  int main()
  {
     try { throw your_exc3(); }
     catch(std::exception const& e) {}
     catch(...) { std::cout << "whoops!" << std::endl; }
  }

  The program above prints "whoops" because the C++ runtime can't
  resolve which exception instance to match in the first catch
  clause.

boost::filesystem::filesystem_error (possibly among others) ought to
be updated to follow this guideline IMO.

BTW, isn't "filesystem::filesystem_error" a little redundant? Anyone
for
        typedef filesystem_error error;

?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk