What happens if an exception is throws from an, object's
constructor and object's destructor?

Answers were Sorted based on User's Feedback



What happens if an exception is throws from an, object's constructor and object's destru..

Answer / dee

if the exception is thrown in constructor, its caught or
function terminate will eb called.
U cannot throw exception from destructor

Is This Answer Correct ?    6 Yes 2 No

What happens if an exception is throws from an, object's constructor and object's destru..

Answer / truong

1. If exception is thrown in the constructor, the destructor will be not called.
2. If exception is thrown in the destructor of a static object, exception will be catch in the main.

Is This Answer Correct ?    3 Yes 0 No

What happens if an exception is throws from an, object's constructor and object's destru..

Answer / 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

What happens if an exception is throws from an, object's constructor and object's destru..

Answer / akshay

constructor:
the destructors of all the member objects that were
correctly created are called, then code goes to the catch
statement if any

dtors:
legally allowed, however, it should be caught within the
function. if it is not caught, then it may lead to a call to
terminate() function. this call would happen in the case
when the destructor was itself called due to stack unwinding
happening because of another exception in probably some
other function.

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More C++ General Interview Questions

When do we run a shell in the unix system?

0 Answers  


when can we use virtual destructor?

7 Answers   HCL, HP, Virage Logic,


Do the parentheses after the type name make a difference with new?

0 Answers  


Describe run-time type identification?

1 Answers  


Will c++ be replaced?

0 Answers  


What is size of Empty Class?

3 Answers   Persistent,


What is the best book for c++ beginners?

0 Answers  


What is the difference between set and map in c++?

0 Answers  


Differentiate between an external iterator and an internal iterator? What is the advantage of an external iterator.

0 Answers  


What are the advantages of using a pointer?

0 Answers  


Evaluate: int fn(int v) { if(v==1 || v==0) return 1; if(v%2==0) return fn(v/2)+2; else return fn(v-1)+3; } for fn(7); a) 10 b) 11 c) 1

4 Answers   Quark,


Who discovered c++?

0 Answers  


Categories