1try {
2 //do something
3} catch (const std::exception& e) {
4 std::cout << e.what(); // information from error printed
5}
1#include <stdexcept>
2#include <limits>
3#include <iostream>
4
5using namespace std;
6
7void MyFunc(int c)
8{
9 if (c > numeric_limits< char> ::max())
10 throw invalid_argument("MyFunc argument too large.");
11 //...
12}
1// exceptions
2#include <iostream>
3using namespace std;
4
5int main () {
6 try
7 {
8 throw 20;
9 }
10 catch (int e)
11 {
12 cout << "An exception occurred. Exception Nr. " << e << '\n';
13 }
14 return 0;
15}