Bloomberg LP Interview Question
Software Engineer / Developersyes, we should never throw an exception from a destructor because a destructor can also be invoked during the stack unwinding process. Stack unwinding happens when an exception has be thrown and handling block is few stack frames below the place from where the exception is thrown. So when you throw an exception from a destructor , your run time has to make a choice whether to handle the newly thrown exception(from Destructor) or to handle the exception that was already being processed. It would simple terminate the process.
you should not throw exception from destructor. that can cause problems with stack unwind.
- NewStart April 21, 2010you can throw from constructor but destructor will not be called on object