c++ – terminate called after throwing an instance of char const* in string function
c++ – terminate called after throwing an instance of char const* in string function
Dont throw strings (const char*
):
throw failed because of hour;
make an exception class
:
class MyException : public std::exception
{
public:
MyException(const char* err) : std::exception(err) {}
};
and throw
that:
throw MyException(failed because of hour);
and then catch
it:
try
{
// code that might throw
}
catch(const MyException& ex)
{
// process exception
}
if an exception is thrown and not caught (your current case) then terminate
is called.
c++ – terminate called after throwing an instance of char const* in string function
Related posts on c++ :