Answered step by step
Verified Expert Solution
Question
1 Approved Answer
As we discussed this quarter, throwing exceptions from destructors is generally considered to be extremely problematic, so much so that we're advised never to do
As we discussed this quarter, throwing exceptions from destructors is generally considered to be extremely problematic, so much so that we're advised never to do it. Yet C++ doesn't explicitly forbid it, so it would be possible to implement a class whose destructor threw an exception.
Suppose you did write such a class:
class Throwing { public: Throwing() { } ~Throwing() { throw std::runtime_error{"doh!"}; } };
- Are there any circumstances in which this throwing destructor would be problematic? If so, demonstrate such a circumstance (e.g., by writing a C++ function that would be problematic) and briefly explain what is problematic about it. If not, demonstrate what a problematic destructor would actually look like (i.e., what else would need to be true about it, if just throwing an exception isn't enough?).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started