Test Series - cpp

Test Number 56/102

Q: In nested try catch blocks, if both inner and outer catch blocks are unable to handle the exception thrown, then ______________
A. Compiler executes only main()
B. Compiler throws compile time errors about it
C. Program will run without any interrupt
D. Program will be termianted abnormally
Solution: If no inner/outer catch handler is avaliable to handle the exception then as usual the program will show abnormal behaviour.
Q: Which function is invoked when an unhandled exception is thrown?
A. stop()
B. aborted()
C. terminate()
D. abandon()
Solution: terminate() function is called/invoked incase any exception is not handled properly.
Q: How one can restrict a function to throw particular exceptions only?
A. By defining multiple try-catch blocks inside a function
B. By defining a generic function within a try-catch block
C. By defining a function with throw clauses
D. Not allowed in C++
Solution: We can use throw clause to mention the exceptions that a function can throw. Hence restricting the function to throw some particular exceptions only.
Q: Which function is invoked when we try to throw an exception that is not supported by a function?
A. indeterminate()
B. unutilized()
C. unexpected()
D. unpredicted()
Solution: As the exception is not supported by the function so it does not know what to do about the exception in that case it call the unexpected() function of the STL library.
Q: Return type of uncaught_exception() is________________
A. int
B. bool
C. char *
D. double
Solution: Return type of uncaught exceptions are bool.
Q: Which alternative can replace the throw statement?
A. for
B. break
C. return
D. exit
Solution: throw and return does the same job as return a value. So it can be replaced.
Q: What are the disadvantages if use return keyword to return error codes?
A. You have to handle all exceptional cases explicitly
B. Your code size increases dramatically
C. The code becomes more difficult to read
D. All of the mentioned
Solution: As we are using return for each and every exception, It will definitely increase the code size.
Q: What is most suitable for returning the logical errors in the program?
A. Use constructor and destructor
B. Set a global error indicator
C. Use break keyword
D. Use final keyword
Solution: Set a global error indicator is most suitable for returning the logical errors in the program.
Q: Pick out the correct statement for error handling alternatives.
A. Terminate the program
B. Use the stack
C. Exit from the block
D. Use the queue
Solution: When an error is raised means, it will be pushed into stack and it can be corrected later by the programmer.
Q: What will happen when an exception is not processed?
A. It will eat up a lot of memory and program size
B. Terminate the program
C. Crash the compiler
D. Displays proper output
Solution: As in the case of not using an exception, it will remain useless in the program and increase the code complexity.

You Have Score    /10