This is a simple Try Block example of C++ Exception. In this example we are going to show how to try block can be localized in a function.
#include <iostream> void fun(int test) { try{ if(test) throw test; } catch(int i) { cout << "Caught First! Example #: " << i << '\n'; } } int main() { cout << "start\n"; fun(1); fun(2); fun(0); fun(3); cout << "end"; return 0; }