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

Why #include is used?

0 Answers  


Explain the different access specifiers for the class member in c++.

0 Answers  


Explain the operation of overloading of an assignment operator.

0 Answers  


Give a very good method to count the number of ones in a "n" (e.g. 32) bit number.

3 Answers  


What is low level language in simple words?

0 Answers  






What is the difference in size of this two clasees? Class A { int a; char c; float f; } Class B { float f; char c; int a; }

4 Answers  


What should main() return in c and c++?

0 Answers  


What doescout<<(0==0) print out a) 0 b) 1 c) Compiler error: Lvalue required

0 Answers  


What is the use of this pointer in c++?

0 Answers  


pls help.. paper bills.. 1000, 500, 100, 50, 20, 10, 5, 1.. create a program that will count all the paper bills in the number being input.. example: enter a number: 3886 there is/are: 3 ->1000 1 ->500 3 ->100 1 ->50 1 ->20 1 ->10 1 ->5 1 ->1 example2: enter a number: 728 there is/are: 0 ->1000 1 ->500 2 ->100 0 ->50 1 ->20 0 ->10 1 ->5 3 ->1

4 Answers  


What are the restrictions apply to constructors and destructors?

0 Answers  


How do I download c++?

0 Answers  


Categories