C++ Programming Multiple Choice Questions - Exception Handling
This section focuses on the "Exception Handling" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which keyword is used to handle the expection?
A. Try
B. Throw
C. Catch
D. None of the above
View Answer
Ans : C
Explanation: Catch keyword is used to handle the expection
2. Which is used to throw a exception?
A. Try
B. Throw
C. Catch
D. None of the above
View Answer
Ans : B
Explanation: Throw is used to throw a exception.
3. Which exception is thrown by dynamic_cast?
A. bad_cast
B. bad_typeid
C. bad_exception
D. bad_alloc
View Answer
Ans : A
Explanation: bad_cast exception is thrown by dynamic_cast.
4. How do define the user-defined exceptions?
A. Inherting & overriding exception class functionlity
B. Overriding class functionlity
C. Inherting class functionlity
D. None of the above
View Answer
Ans : A
Explanation: By using Inherting & overriding exception class functionlity
5. We can prevent a function from throwing any exceptions.
A. TRUE
B. FALSE
C. May Be
D. Can't Say
View Answer
Ans : A
Explanation: True, We can prevent a function from throwing any exceptions.
6. In nested try block, if inner catch handler gets executed, then __________?
A. Program execution stops immediately.
B. Outer catch handler will also get executed.
C. Compiler will jump to the outer catch handler and then executes remaining executable statements of main().
D. Compiler will execute remaining executable statements of outer try block and then the main().
View Answer
Ans : D
Explanation: In nested try block, if inner catch handler gets executed, then Compiler will execute remaining executable statements of outer try block and then the main().
7. Return type of uncaught_exception() is ___________.
A. int
B. bool
C. char *
D. double
View Answer
Ans : B
Explanation: Return type of uncaught_exception() is bool.
8. Which of the following statements are true about Catch handler?
i) It must be placed immediately after try block T.
ii) It can have multiple parameters.
iii) There must be only one catch handler for every try block.
iv) There can be multiple catch handler for a try block T.
v) Generic catch handler can be placed anywhere after try block.
A. Only i, iv, v
B. Only i, ii, iii
C. Only i, iv
D. Only i, ii
View Answer
Ans : C
Explanation: Only i, iv statements are true about Catch handler.
9. If inner catch handler is not able to handle the exception then__________ .
A. Compiler will look for outer try handler
B. Program terminates abnormally
C. Compiler will check for appropriate catch handler of outer try block
D. None of the above
View Answer
Ans : C
Explanation: If inner catch handler is not able to handle the exception then Compiler will check for appropriate catch handler of outer try block.
10. Which type of program is recommended to include in try block?
A. Static memory allocation
B. Dynamic memory allocation
C. Const reference
D. Pointer
View Answer
Ans : B
Explanation: While during dynamic memory allocation, Your system may not have sufficient resources to handle it, So it is better to use it inside the try block.
Also check :
Discussion