try {
throw 10; //Error Detected and "Thrown" to catch block
}
catch (char *excp) { //if error is thrown matches this block, exec
cout << "Caught " << excp;
}
catch (...) { //default case
cout << "Default Exception
";
}
#include <iostream>
using namespace std;
int main()
{
int x = -1;
// Some code
cout << "Before try
";
try {
cout << "Inside try
";
if (x < 0)
{
throw x;
cout << "After throw (Never executed)
";
}
}
catch (int x ) {
cout << "Exception Caught
";
}
cout << "After catch (Will be executed)
";
return 0;
}