#include <iostream>
#include <exception>
using namespace std;

void ThrowExcept () {

  try{
    cout << "Function throws an exception" << endl;
    throw exception();
  }
  catch (exception &, bad_alloc &) {

    cout << "Caught in function, rethrow" << endl;
    throw;
  }
  

}

int main() {
  //try {
    int * a = new int[50000000000000000]; 
    //}
    //catch (bad_alloc) {
  
    //cout << "not enough memory" << endl;
    //}

  try {
    cout << "Main invokes function" << endl;
    ThrowExcept();
    cout << "blah blah" << endl;
  }
  catch (bad_alloc) {

    cout << "Handled in main" << endl;

   }

  cout << "Final line" << endl;

}

      


