Test Series - cpp

Test Number 55/102

Q: Where should we place catch block of the derived class in a try-catch block?
A. Before the catch block of Base class
B. After the catch block of Base class
C. Anywhere in the sequence of catch blocks
D. After all the catch blocks
Solution: C++ asks the programmer to place the catch block of derived class before a catch block of the base class, otherwise derived catch block will never be executed.
Q: What id the syntax for catching any type of exceptions?
A. catch(Exception e)
B. catch(…)
C. catch(Exception ALL)
D. catch(ALL)
Solution: catch(…) is used in C++ to catch all types of exceptions in a single catch block.
Q: Uncaught exception leads to ______________
A. termination of program
B. successful execution of programs
C. no effect on the program
D. execution of other functions of the program starts
Solution: Uncaught exceptions in a program leads to the termination of a program.
Q: An uncaught handler returns to _______________
A. main function
B. its caller
C. its callee
D. waits there for some time
Solution: Uncaught handler returns to its callee(i.e. the function it is called by).
Q: Header file used for exception handling in C++?
A. 
B. 
C. 
D. 
Solution:  header file is used to use exception handler in C++.
Q: The C++ code which causes abnormal termination/behaviour of a program should be written under _________ block.
A. try
B. catch
C. finally
D. throw
Solution: Code that leads to the abnormal termination of the program should be written under the try block.
Q: Exception handlers are declared with ____________ keyword.
A. try
B. catch
C. throw
D. finally
Solution: C++ uses catch block to handle any exceptions that occur during run-time of the program.
Q: Which of the following statements are correct about Catch handler?

i. It must be placed immediately after the try block 
ii. It can have more than one parameters
iii. There must be one and only one catch handler for every try block
iv. There can be multiple catch handler for a try block 
v. General catch handler can be kept anywhere after try block.
A. i, iv, v
B. i, ii, iii
C. i, iv
D. i, ii
Solution: A catch block should always be placed after the try block and there can be multiple catch block following a try block.
Q: In nested try-catch block, if the inner catch block gets executed, then______________
A. Program stops immediately
B. Outer catch block also executes
C. Compiler jumps to the outer catch block and executes remaining statements of the main() function
D. Compiler executes remaining statements of outer try-catch block and then the main() function
Solution: The inner catch block will be executed then remaining part of the outer try block will be executed and then the main bock will be executed.
Q: If inner catch block is unable to handle the exception thrown then__________
A. The compiler looks for the outer try-catch block
B. Program stops abnormally
C. The compiler will check for appropriate catch handler of the outer try block
D. The compiler will not check for appropriate catch handler of the outer try block
Solution: In such cases, the compiler will try to find an appropriate outer catch block to handle the exception otherwise if nothing is there then occurs the abnormal behaviour of the program.

You Have Score    /10