try,catch and exception c++ code example
Example 1: C++ try catch
try {
//do something
} catch (const std::exception& e) {
std::cout << e.what(); // information from error printed
}
Example 2: try statement in c++
// exceptions
#include <iostream>
using namespace std;
int main () {
try
{
throw 20;
}
catch (int e)
{
cout << "An exception occurred. Exception Nr. " << e << '\n';
}
return 0;
}