title: Can't catch class derived from std::exception by reference to std::exception
body: <p>I created a custom exception class that derives from std::exception. </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Exception : std::exception {
  public:
      const char* what() const noexcept override {
          return "test";
      }
  };
  
  int main() {
      try {
          throw Exception();
      } catch (std::exception&amp; e) {
          std::cout &lt;&lt; e.what() &lt;&lt; std::endl;
      }
  }   
  </code></pre>
  
  <p>This program, when compiled by g++ -stdc++=17 on Ubuntu, causes the exception to not get caught by the catch block, even though catching by reference is supposed to catch derived exceptions too. It calls std::terminate, even though it happens in a try block that catches its base class by reference. Same thing happens if Exception inherits from std::runtime_error and passes "test" to the std::runtime_error constructor in its own constructor. Normally the solution would be to only catch using Exception, but in my original code I need to catch different types of exceptions, all of which inherit from std::exception. Why does this happen? Does catching by reference to base not work? How can I catch all exceptions deriving from std::exception using one catch block?</p>