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 ?    5 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

what is the size of this class class size { public: char data1; double d; int data2; char data3; double data4; short data5; }; please explain the padding for these double variables.

9 Answers  


Write the program for fibonacci in c++?

20 Answers   TATA, Wipro,


Explain the difference between 'operator new' and the 'new' operator?

1 Answers   Lucent, TCS,


What is expression parser in c++

0 Answers   Mphasis,


Can inline functions have a recursion? Give the reason?

3 Answers  






Why for local variables the memory required to hold the variable is allocated from the program stack and for new its allocated from the heap?

1 Answers  


what are the iterator and generic algorithms.

0 Answers  


Write a C/C++ program to show the result of a stored procedure "PROC_RESET_MAIL" on database "USER_NOTIFY".

2 Answers   ABC, Accenture, HCL, Webyog, DataLand,


What is the best sorting algorithm, when there is a large amount of data, that cannot be fit in the main memory. ?

1 Answers   Yahoo,


Enter n no. of element and delete value from desire position

1 Answers  


Is structure can be inherited?

5 Answers   HP, ST Micro,


If there are 1 to 100 Numbers in array of 101 elements. Which is the easy way to find repeated number?

2 Answers   Persistent,






Categories