wap to show exception using try throw and catch block.
#include <iostream>
using namespace std;
int main()
{
int num = -1;
cout << "Before try \n";
try {
cout << "try \n";
if (num < 0)
{
throw num;
cout << "After throw (Never executed) \n";
}
}
catch (int num) {
cout << "Exception Caught \n";
}
cout << "After exception catch \n";
return 0;
}
Comments
Leave a comment