C++ examples for Statement:try catch
Throw string value as exception
#include <iostream> #include <string> using namespace std; void Inner()/* w ww . ja va2 s .c o m*/ { throw string("Error!"); } void Outer() { try { Inner(); } catch (string excep) { cout << "Outer caught an exception: "; cout << excep << endl; throw; } } int main() { try { Outer(); } catch (string excep) { cout << "main caught an exception: "; cout << excep << endl; } return 0; }