Mega Code Archive

 
Categories / C++ / Language
 

Throw exception out of function

#include <iostream> using namespace std; void XHandler(int test){     cout << "Inside XHandler, test is:" << test << endl;     if(test) throw test; } int main(void){    cout << "Start: " << endl;    try {       cout << "Inside try block." << endl;       XHandler(1);       XHandler(2);       XHandler(0);     }    catch(int i) {       cout << "Caught an exception. Value is: ";       cout << i << endl;     }    cout << "End"; }