Составил из кода пример непонятной мне работы try/catch По непонятной мне причине catch не срабатывает, и я получаю: rilium@cl-t063-361cl:/tmp$ g++ test2.cpp && ./a.out terminate called after throwing an instance of 'spectra::exceptions::allocation_error' Aborted Хотя если поменять catch(std::exception& ex), на catch(std::bad_alloc& ex) или catch(spectra::exceptions::spectra_exception& ex) Все работает как я и ожидаю. Что не так? И как правильно сделать такую модель работоспособной? #include <iostream> #include <exception> #include <new> namespace spectra { namespace exceptions { class spectra_exception : public std::exception { }; class allocation_error : public std::bad_alloc, public spectra::exceptions::spectra_exception { public: virtual const char* what() const throw(); }; const char* allocation_error::what() const throw() { return "Not enough memory"; } } } int main() { try { throw(spectra::exceptions::allocation_error()); } catch(std::exception& ex) { std::cout << "Error: " << ex.what() << std::endl; } }