1  #include <iostream>
  2  #include <stdexcept>
  3  using namespace std;
  4  
  5  int f1()
  6  {
  7    try
  8    {
  9      throw runtime_error("Exception in f1");
 10    }
 11    catch (exception& ex)
 12    {
 13      cout << "Exception caught in function f1" << endl;
 14      cout << ex.what() << endl;
 15      throw; // Rethrow the exception
 16    }
 17  }
 18  
 19  int main()
 20  {
 21    try
 22    {
 23      f1();
 24    }
 25    catch (exception& ex)
 26    {
 27      cout << "Exception caught in function main" << endl;
 28      cout << ex.what() << endl;
 29    }
 30  
 31    return 0;
 32  }