Exception Handling
- What is the output of this program?
#include <iostream>
#include <typeinfo>
using namespace std;
class N
{
};
int main()
{
char ch; float n;
if (typeid(ch) != typeid(n))
cout << typeid(ch).name() << endl;
cout << typeid(N).name();
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
We are checking the type id of char and float as they are not equal, We are printing c and 1N.
- What is the output of this program?
#include <iostream>
using namespace std;
void DivFunction(const double num1, const double num2);
int main()
{
double option1=20, option2=5;
try
{
DivFunction(option1, option2);
}
catch (const char* S)
{
cout << "Bad Operator caught: " << S;
}
return 0;
}
void DivFunction(const double num1, const double num2)
{
double Res;
if (num2 == 0)
throw "Division by zero not allowed";
Res = num1 / num2;
cout << Res;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
We are dividing 20 and 5 in this program and we are using the throw statement in the function block.
- What operation can be performed by destructor?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
It will be used to free all the resources that are used by the block of code during execution.
- What is the use of RAII in c++ programming?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Improve the exception safety
- How many levels are there in exception safety?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The three levels of exception safety are basic, strong and no throw.