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 is a float in c++?
Define a constructor - what it is and how it might be called (2 methods)?
What is the difference between global int and static int declaration?
Write about the retrieval of n number of objects during the process of delete[]p?
What is insertion sorting?
What is a volatile variable in c++?
Is oops and c++ same?
What is the difference between the functions rand(), random(), srand() and randomize()?
Is it possible to provide special behavior for one instance of a template but not for other instances?
What is the difference between C and CPP?
Why c++ is faster than java?
How can an improvement in the quality of software be done by try/catch/throw?
What are features of c++?
Is there structure in c++?
Describe linked list using C++ with an example.