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


Please Help Members By Posting Answers For Below Questions

What are the benefits of c++?

565


Write a code/algo to find the frequency of each element in an array?

599


What is insertion sorting?

659


Can I have a reference as a data member of a class? If yes, then how do I initialise it?

704


What is microsoft c++ redistributable?

608






Where is atoi defined?

577


Is java as fast as c++?

595


Write a short code using c++ to print out all odd number from 1 to 100 using a for loop

580


How can an improvement in the quality of software be done by try/catch/throw?

586


What is the difference between c++ and turbo c++?

584


What is the auto keyword good for in c++?

617


Can you explicitly call a destructor on a local variable?

599


Can we make copy constructor private in c++?

591


What is the syntax for a for loop?

594


Is vector a class in c++?

592