ExamVeda
Login
Home
11
Which of the following statements is true about the 'finally' block in C++ exception handling?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
12
What is the purpose of re-throwing an exception in C++?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
13
Which header file is necessary for exception handling in C++?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
14
What is the function of the 'assert' macro in C++?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
15
How do you define your own exception class in C++?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
16
What is the default behavior of an uncaught exception in C++?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
17
What is the purpose of the 'std::runtime_error' class in C++ exception handling?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
18
How do you specify that a function may throw an exception in C++?
Discuss
Answer & Solution
Answer: Option D
Solution:
The correct answer is Option D: Using the 'noexcept' specifier
Here's why:
Exception handling in C++ allows you to deal with unexpected problems that occur during the execution of a program.
A function can signal that something went wrong by "throwing" an exception.

Let's break down the options:
Option A: Using the 'throws' keyword - The `throws` keyword is not used in standard C++ for specifying exceptions. Languages like Java use `throws`.
Option B: Using the 'exception' keyword - The `exception` keyword is related to exception classes but not to specifying if a function *might* throw an exception.
Option C: Using the 'throws()' specifier - This is also incorrect. C++11 introduced `noexcept` for this purpose. Older C++ standards used something called exception specifications but they are largely deprecated and not the best practice to use anymore.
Option D: Using the 'noexcept' specifier - The `noexcept` specifier is used to specify whether a function may throw an exception. If a function is declared `noexcept`, it promises *not* to throw any exceptions. If it *does* throw an exception, the program might terminate abruptly. The absence of `noexcept` does *not* mean the function *will* throw, only that it *might*.
19
Which of the following is true about the 'noexcept' specifier in C++?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
20
What is the purpose of the 'std::bad_alloc' class in C++ exception handling?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board