I'm using substr for generating substring. How I can catch substr exception? For instance:
terminate called after throwing an instance of 'std::out_of_range'
Like this:
try
{
/// use substr
}
catch( std::out_of_range& exception )
{
// print out an error, and fail, or restart if appropriate.
}
try
{
std::string sub = mystring.substr(10,1);
}
catch (std::out_of_range & ex)
{
cout << "caught exception!" << endl;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With