How can one handle a destructor that fails?, C/C++ Programming

How can one handle a destructor that fails?

Posted Date: 3/15/2013 5:17:15 AM | Location : United States





How can one handle a destructor that fails?

A: Write down a message to a log-_le. However do not throw an exception. The C++ rule is that you ought to never throw an exception from a destructor which is being called during the "stack unwinding" procedure of another exception. For instance, if someone says throw Foo(), the stack will be unwound so all of the stack frames among the throw Foo() and the } catch (Foo e) { will get popped. It is called stack unwinding. Throughout stack unwinding, the entire local objects in all those stack frames are destructed. If one of those destructors throws an exception (say it throws a Bar object), the C++ runtime system is in a no-win condition: should it avoid the Bar and end up in the} catch (Foo e) {where it was headed originally? Should it avoid the Foo and look for a } catch (Bare) { handler? There is no good answer: either choice loses information. Thus the C++ language guarantees that it will call terminate() at this point, and terminate() kills the procedure. Bang you''re dead.

 

Posted by | Posted Date: 3/15/2013 5:17:54 AM


Related Discussions:- How can one handle a destructor that fails?, Assignment Help, Ask Question on How can one handle a destructor that fails?, Get Answer, Expert's Help, How can one handle a destructor that fails? Discussions

Write discussion on How can one handle a destructor that fails?
Your posts are moderated
Related Questions
c program to construct a structure: struct sensus                 {                                 char name[30];                                 long int population;

in a program for what purpose print f and scan f is used

Explain the For Loop - Computer Programming? Similar to the while statement, for loop is an entry controlled loop and the code of the for loop will be executed itereatively. Th

i am using mobile phone if i want to communicate via massage but that should be very secret

Tell what the derived class inherits or doesn't inherit? A: Inherits: - All data member defined in the parent class (even though such members might not always be accessible

C Program to check FACTORIAL   main() {             int i,j,m,fact,sum=0;           clrscr();           printf("ENTER THE NO.: ");           scanf("%d",&m);

How do one throw polymorphically?               A: Sometimes people write code such as: class MyExceptionBase { }; class MyExceptionDerived : public MyExceptionBase { };

Question: (a) (i) What is recursion? (ii) What advantage is there in its use? (iii) What disadvantage is there in its use? (b) The factorial of a positive number can b

How do you know that your class requires a virtual destructor? A: If at least your class has one virtual function, you must make a destructor for this class virtual. It will let

Problem: (a) (i) What is a structure? (ii) How does a structure differ from an array? (b) Declare a structure, called account, that will contain the following data me