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

Problem 6: Area of a trapezoid can be calculated by the following formula: A=(b1 b2)×h2 where b1 and b2 are the parallel sides or the bases and h is length of height Write a C code of this program

0 Answers   Maxobiz,


write the programme that convert a interger to biniry number

1 Answers   Amazon,


When a function is made inline. Write the situation where inline functions may not work.

2 Answers  


Write a c program for binary addition of two 8 bit numbers.

0 Answers   TCS,


Write an algorithm that determines whether or not an almost complete binary tree is a heap.

0 Answers   TCS,






What is function overriding?

1 Answers  


1. What does the following do: void afunction(int *x) { x=new int; *x=12; } int main() { int v=10; afunction(&v); cout<<v; } a) Outputs 12 b) Outputs 10 c) Outputs the address of v

5 Answers   Quark,


what is the behaviour of C and C++ compiler for the below statements. int *p; p = malloc(100); Is the behaviour same ? or different ?

2 Answers  


What is expression parser in c++

0 Answers   Mphasis,


Badboy is defined who has ALL the following properties: 1. Does not have a girlfriend and is not married. 2. He is not more than 23 years old. 3. The middle name should be "Singh" 4. The last name should have more than 4 characters. 5. The character 'a' should appear in the last name at least two times. 6. The name of one of his brothers should be "Ram" Write a method: boolean isBadBoy(boolean hasGirlFriend , boolean isMarried, int age , String middleName , String lastName , String[] brotherName); isHaveGirlFriend is true if the person has a girlfriend isMarried is true if the person is married age is the age of the person middleName is the middle name of the person lastName is the last name of the person brotherName is the array of the names of his brothers

1 Answers  


Is there something that we can do in C and not in C++?

14 Answers   Patni,


Which algorithm do you like the most? Why?

2 Answers   Google,






Categories