Machine-translated by Google. Questions are authored in English.
Top

Exception Handling Questions and Answers

1.

Exception handling is not meant to handle problems for which case ?

(i) termination of program
(ii) handle return value representing error
(iii) hand return a legal value and leave the program in an illegal state
(iv) call an error handler function

Exam Year(s)

MH SET - 2023, SET Exam - 2023,

Answer: C

The key is (iv) only, and the source behind it could not be traced.

The four items are the usual ways a program can deal with a run-time error without exceptions: terminate, return an error value, return a legal value and leave the program in an illegal state, or call an error-handler function. Exception handling is introduced as a replacement for those approaches, and the question asks which case it is not meant for. The key picks the call to an error handler function.

The wording is unclear. A search found a similar list of alternatives to exceptions in a C++ textbook but nothing that names (iv) as the one exception handling is not meant for, so the answer rests on the key. Options A, B and D each include (i), (ii) or (iii), which the key treats as cases exceptions do cover.

Please log in or register to report this question.

2.

In exception handling, which block is executed regardless of whether an exception occurs ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: C

The block is finally.

In languages such as Java, C# and Python, a finally block after try/catch runs whether the try block completes normally, throws an exception that is caught, or throws one that is not caught. It is used for cleanup, such as closing files and releasing locks.

The try block holds the code that may fail, and it stops at the first exception. A catch block runs only when a matching exception is thrown. throw is a statement that raises an exception, not a block that always runs.

Please log in or register to report this question.

3.

Which of the following are two special functions that are meant for handling exception, that occur during exception handling itself ?

Exam Year(s)

UGC NET - 2012,

Answer: A

The two special functions that handle exceptions arising during exception handling are terminate() and unexpected(), and both have the return type void. The unexpected() function is called when a function throws an exception that is not in its exception specification, and terminate() is called when no handler is found or when exception handling itself fails.

The options with a non-void version of either function are wrong, since in C++ both are declared as void functions that do not return.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Exception Handling Questions and Answers || Exception Handling MCQ Questions and Answers || Exception Handling GK Questions and Answers || Exception Handling GK MCQ Questions || Exception Handling Multiple Choice Questions and Answers || Exception Handling GK || GK on Exception Handling || Object Oriented Programming Questions and Answers || Object Oriented Programming MCQ Questions and Answers || Object Oriented Programming GK Questions and Answers || GK on Object Oriented Programming