how to catch an exception c++ code example
Example 1: throw exception c++
#include <stdexcept>
#include <limits>
#include <iostream>
using namespace std;
void MyFunc(int c)
{
if (c > numeric_limits< char> ::max())
throw invalid_argument("MyFunc argument too large.");
//...
}
Example 2: c++ try
try {
//do
} catch (...){
//if error do
}