What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int num = 3;
string str_bad = "wrong number used";
try
{
if ( num == 1 )
{
throw 5;
}
if ( num == 2 )
{
throw 1.1f;
}
if ( num != 1 || num != 2 )
{
throw str_bad;
}
}
catch (int a)
{
cout << "Exception is: " << a << endl;
}
catch (float b)
{
cout << "Exception is: " << b << endl;
}
catch (...)
{
cout << str_bad << endl;
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main ()
{
int num = 3;
string str_bad = "wrong number used";
try
{
if ( num == 1 )
{
throw 5;
}
if ( num == 2 )
{
throw 1.1f;
}
if ( num != 1 || num != 2 )
{
throw str_bad;
}
}
catch (int a)
{
cout << "Exception is: " << a << endl;
}
catch (float b)
{
cout << "Exception is: " << b << endl;
}
catch (...)
{
cout << str_bad << endl;
}
return 0;
}
A. Exception is 5
B. Exception is 1.1f
C. Wrong number used
D. Exception is 1.6g
Answer: Option C
Join The Discussion