Actually:
#include <iostream> class Exception : std::exception { public: Exception(const std::string &&whatStr) noexcept : whatStr(std::move(whatStr)) { } Exception(const std::string &whatStr) noexcept : whatStr(whatStr) { } ~Exception() noexcept=default; const char* what() const noexcept override { return whatStr.c_str(); } private: std::string whatStr; }; int main(int argc, char *argv[]) { try { throw Exception("hello"); } catch(std::exception& e) { std::cout<< e.what(); } return 0; } So std::terminate happens, because exception& e does not catch Exception . If add:
catch(Exception& e) { std::cout<< e.what(); } That he understandably catches. But why not catch the base class?