Mega Code Archive

 
Categories / C++ / Language
 

Localize a trycatch to a function

#include <iostream> using namespace std; void myFunction(int test) {   try{     if( test )         throw test;   }catch(int i) {     cout << "Caught Exception #: " << i << '\n';   } } int main() {   cout << "Start\n";   myFunction(1);   myFunction(2);   myFunction(0);   myFunction(3);   cout << "End";   return 0; }