Exception Handling - placement practice test

Exception Handling - placement practice test


1. An exception is thrown using _____________ keyword in CPP.

a. throws
b. throw
c. threw
d. thrown
View Answer / Hide Answer

ANSWER: b. throw




2. The code of statements which may cause abnormal termination of the program should be written under_________ block

a. try
b. catch
c. Finally
d. None of these
View Answer / Hide Answer

ANSWER: a. try




3. Exception handlers are declared with ____________ keyword

a. Try
b. catch
c. throw
d. finally
View Answer / Hide Answer

ANSWER: b. catch




4. Catch handler can have multiple parameters.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False
Explanation: A catch handler should contain only one parameter of any type. Multiple parameters are not allowed inside catch handler.




5. Which of the following statements are true about Catch handler ?

1. It must be placed immediately after try block T
2. It can have multiple parameters
3. There must be only one catch handler for every try block
4. There can be multiple catch handler for a try block T
5. Generic catch handler can be placed anywhere after try block.

a. Only 1, 4, 5
b. Only 1, 2, 3
c. Only 1, 4
d. Only 1, 2
View Answer / Hide Answer

ANSWER: c. Only 1, 4




6. A try block can be nested under another try block –

a. Yes
b. No
View Answer / Hide Answer

ANSWER: a. Yes




7. In nested try blocks, there is no need to specify catch handler for inner try block. Outer catch handler is sufficient for the program.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False
Explanation: For every try block, there must be at least one catch hander. Otherwise, compiler will generate error.




8. 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 / Hide Answer

ANSWER: d. Compiler will execute remaining executable statements of outer try block and then the main()




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 these
View Answer / Hide Answer

ANSWER: c. Compiler will check for appropriate catch handler of outer try block




10. Generic catch handler must be placed at the end of all the catch handlers

a. True
b. False
View Answer / Hide Answer

ANSWER: a. True




11. Generic catch handler is represented by ______________

a. catch(..,)
b. catch(---)
c. catch(…)
d. catch( void x)
View Answer / Hide Answer

ANSWER: c. catch(…)




12. In nested try blocks, if both inner and outer catch handlers are not able to handle the exception, then______________

a. Compiler executes only executable statements of main()
b. Compiler issues compile time errors about it
c. Program will be executed without any interrupt
d. Program will be terminated abnormally
View Answer / Hide Answer

ANSWER: d. Program will be terminated abnormally




13. Functions called from within a try block may also throw exception

a. True
b. False
View Answer / Hide Answer

ANSWER: a. True




14. Irrespective of exception occurrence, catch handler will always get executed.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False
Explanation: catch handler will only get execute when exception occurs at runtime




15. Throwing an unhandled exception causes standard library function _______________ to be invoked.

a. stop()
b. aborted()
c. terminate()
d. abandon()
View Answer / Hide Answer

ANSWER: c. terminate()




16. An exception can be of only built-In type.

a. True
b. False
View Answer / Hide Answer

ANSWER: b. False
Explanation:: An exception can be of any type, including class type that we create.




17. We can prevent a function from throwing any exceptions.

a. True
b. False
View Answer / Hide Answer

ANSWER: a. True




18. How can we restrict a function to throw certain exceptions?

a. Defining multiple try and catch block inside a function
b. Defining generic function within try block
c. Defining function with throw clause
d. It is not possible in CPP to restrict a function
View Answer / Hide Answer

ANSWER: c. Defining function with throw clause




19. Attempting to throw an exception that is not supported by a function call results in calling _____________ library function.

a. indeterminate()
b. unutilized()
c. unexpected()
d. unpredicted()
View Answer / Hide Answer

ANSWER: c. unexpected()




20. Return type of uncaught_exception() is________________

a. int
b. bool
c. char *
d. double
View Answer / Hide Answer

ANSWER: b. bool




21. Can we write throw clause inside catch handler?

a. Yes
b. No
View Answer / Hide Answer

ANSWER: a. Yes
Explanation: In case of re-throwing an exception, we can use throw clause in a catch handler.




22. Can we define our exceptions in CPP?

a. Yes
b. No
View Answer / Hide Answer

ANSWER: a. Yes
Explanation : We can define our own exception by inheriting and overriding exception class functionality.



Post your comment

You may like