WAP to show multiple throw statement execution by using suitable example.
#include <iostream>
#include<conio.h>
using namespace std;
int main()
{
int a[3] = {-1,2};
for(int i=0; i<2; i++)
{
int exception = a[i];
try
{
if (exception > 0)
// throwing numeric value as exception
throw exception;
else
// throwing a character as exception
throw 'exception';
}
catch (int exception) // to catch numeric exceptions
{
cout << "Integer exception\n";
}
catch (char exception) // to catch character/string exceptions
{
cout << "Character exception\n";
}
}
}
The above code illustrates multiple catch blocks to handle different types of exceptions in different ways
Comments
Leave a comment