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
A: The procedure of encoding the parameter types along with the function/method name into a unique name is called as name mangling. The inverse procedure is called demangling. F

Why are all header files not declared in every C program? - Declaring all header files in each program would result in increase in overall file size and load of the program. It

how do i write a c++ program that will input a number and output its factorial using the while loop

What is the difference between structure and class? - Members of structures are public while those of a class are private. - Classes provide data hiding while structures don

how to fill the blank space in4*4 matrix?

write a c program to compute a padovan string

In this problem, you will write a program that implements two algorithms for performing exact inference given a Bayesian network, namely, enumeration and variable elimination. Your

Write a function that has two int parameters num and n, and returns TRUE when the nth bit in num is 1, otherwise FALSE. This function should use the function in the above problem.

Write an algorithm for multiplication of two sparse matrices using Linked Lists.

#questio#A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concate