-
What is the output of this program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int n = 5;
string str = "Exception Caught: Wrong number used";
try
{
if ( n == 1 )
{
throw 10;
}
if ( n == 2 )
{
throw 3.5f;
}
if ( n != 1 || n != 2 )
{
throw str;
}
}
catch (int p)
{
cout << "Exception value is: " << p << endl;
}
catch (float q)
{
cout << "Exception value is: " << q << endl;
}
catch (string str)
{
cout << str << endl;
}
return 0;
}
-
- Exception value is: 10
- Compilation Error
- Exception value is: 3.5
- Exception Caught: Wrong number used
- None of these
Correct Option: D
As we are giving 5 to n, It is arising an exception named
“Exception Caught: Wrong number used”.