answersLogoWhite

0


Best Answer

If a destructor throws an exception, the instance is left in an invalid state. When an exception is thrown, the destructor automatically terminates at the point of the throw, unwinding the call stack until an exception handler is found (if one is provided). However, any resources yet to be released by the destructor, including all the instance's base classes, cannot be destroyed.

When writing your own destructors, it is important to never throw an exception. If an exception could be thrown from within your destructor, you must catch it and handle it within the same destructor -- you must not rethrow the exception.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is issue in throwing an exception in a destructor?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

You cannot throw an exception from a destructor?

Sure you can, but it's never a good idea. You must never allow an exception to escape from a destructor. To do so would terminate the destructor prematurely, unwinding the call stack in search of an exception handler. This means that any remaining resources consumed by the instance, including its base classes, would be left in an invalid state with no possible way to recover those resources besides terminating the program. Any object that has the potential to throw an exception during its own destruction should always be treated with suspicion; it is a major design flaw.


When was Varroa destructor created?

Varroa destructor was created in 2000.


What is the Issue Exception Code code for unit of issue feet?

IEX 4


What is l drago destructor ultimate move?

Dragon Emperor Life Destructor.


Can you throw exception from catch block in net?

Yes. Use C# code as an example: try { int k = 100 / 0; // this will throw an exception } catch (Exception e) { throw new SystemException("Throwing a new exception because of "+ e.Message); }


What does instructor rhyme with?

Destructor


What is the opposite of inventor?

destructor


Is constructors throws exception in C plus plus?

We must throw an exception from constructor in C++, but remember that in case of exception in Ctor, destructor will not be executed and you may have memory leaks. SO make sure all the data members must clean up their mess own. e.g. use smart pointers so in case of excpetion memory will released to free storage.


What actors and actresses appeared in El destructor - 1985?

The cast of El destructor - 1985 includes: Eduardo Palomo


IS Throwing an exception always causes program termination?

No Not necessarily.. You can catch an exception and then continue to execute your program as if nothing happened. If in your catch block you have code like System.exit then your program would terminate.


What is the iPERMS definition of the word Exception?

An exception is a change in the normal flow of batches due to an issue that CANNOT be resolved by other input roles


Can you overload destructor for your class?

No. Classes can only have one destructor, whether you define one yourself or allow the compiler to generate one for you. The compiler-generated destructor is public by default, does not release any memory allocated to any class' member pointers, and is non-virtual, which are the three main reasons for defining your own.