There is a class for exception handling.
class VException : public std::exception { std::string name; public: VException(); VException(std::string); VException(std::string, std::exception&); std::string get_name() const; }; And when an exception is triggered in main, the program drops with the message terminate called after throwing an instance of 'char const*' It is clear that this is a problem when casting std::string to char const* , but it is not clear how to bypass it.
Vector<int>* v; Vector<int>* v1; try { v = new Vector<int>; v1 = new Vector<int>(5); } catch(VException& ex) { std::cout << ex.get_name() << std::endl; } try { v->pop_back(); // тут срабатывает исключение удаления из пустого вектора } catch(VException& ex) { std::cout << ex.get_name().c_str() << std::endl; }
throw- ixScithrow "Ошибка". The exception type turned out to beconst char *, and was not caught by any handler. - yrHeTaTeJlb