What happens if an exception is throws from an, object's
constructor and object's destructor?
Answer Posted / som shekhar
When an exception is thrown from the object constructor,
then the destructor of the object wont be called. But to
undone all the things that happened in the c'tor before the
exception is thrown, you can make use of smart
pointer(either boost smart pointer or std auto pointer).
when an exception is thrown from the destructor the compiler
terminates the application.
So it is advisable not to throw an exception in the
destructor , better to do "something else".
Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What are the benefits of c++?
Write a code/algo to find the frequency of each element in an array?
What is insertion sorting?
Can I have a reference as a data member of a class? If yes, then how do I initialise it?
What is microsoft c++ redistributable?
Where is atoi defined?
Is java as fast as c++?
Write a short code using c++ to print out all odd number from 1 to 100 using a for loop
How can an improvement in the quality of software be done by try/catch/throw?
What is the difference between c++ and turbo c++?
What is the auto keyword good for in c++?
Can you explicitly call a destructor on a local variable?
Can we make copy constructor private in c++?
What is the syntax for a for loop?
Is vector a class in c++?