We are passing the integer and character and catching it by using multiple catch statement. Output: $ g++ gex3.cpp $ a.out integer:10character:x
Question 5.
What is the output of this program?
1. #include 2. using namespace std; 3. int main() 4. { 5. int a = 10, b = 20, c = 30; 6. float d; 7. try 8. { 9. if ((a - b) != 0) 10. { 11. d = c / (a - b); 12. cout
10
-3
15
none of the mentioned
Explanation:-
Answer: Option B. -> -3
We are manipulating the values, if there is any infinite value means, it will raise an exception. Output: $ g++ gex2.cpp $ a.out -3
Question 6.
What is the output of this program?
1. #include 2. using namespace std; 3. int main() 4. { 5. try 6. { 7. throw 1; 8. } 9. catch (int a) 10. { 11. cout
No exception
exception number
exception number: 1
none of the mentioned
Explanation:-
Answer: Option C. -> exception number: 1
If we caught a integer value means, there will be an exception, if it is not a integer, there will
not be a exception. Output: $ g++ gex1.cpp $ a.out exception number: 1
Question 7.
How many runtime error messages associated with exception?
2
4
5
infinite
Explanation:-
Answer: Option B. -> 4
There are four runtime error messages associated with exceptions.They are overflow_error,
range_error, system_error and underflow_error.
Question 8.
How many types of exception handling are there in c++?
1
2
3
4
Explanation:-
Answer: Option B. -> 2
There are two types of exception handling in c++. They are synchronous exception handling and
asynchronous exception handling.
Question 9.
What is the output of this program?
1. #include 2. using namespace std; 3. int main() 4. { 5. double a = 10, b = 5, res; 6. char Operator = '/'; 7. try 8. { 9. if (b == 0) 10. throw "Division by zero not allowed"; 11. res = a / b; 12. cout
10
2
Bad Operator
10 / 5 = 2
Explanation:-
Answer: Option D. -> 10 / 5 = 2
In this program, We are dividing the two variables and printing the result. If any one of the operator
is zero means, it will arise a exception. Output: $ g++ gex.cpp $ a.out 10 / 5 =2