Handling errors is not the most important part of C++ EH machinery?

T

tonytech08

Scenario: An n-deep nesting of RAII contructors and an error occurs at
level n.

One doesn't need the C++ exception machinery to handle the error: an
installable handler (for example, set_new_handler()) can be used to
handle the error. If the error cannot be corrected ("handled") by any
installed handler (perhaps there is a hierarchy of installed
handlers), the stack needs to be unwound (destructors called) on all
the constructed RAII objects. An Unwind() function that would enable
installable handlers to be used in place of C++ exceptions seems to be
curiously missing.

Is the alternative to exceptions described above feasible if there was
an Unwind() function provided by the standard or the platform?
 
T

tonytech08

Huh?  Stack unwinding is the exact opposite of a function call.  How
would you call a function that unwound the stack?

I don't care what mechanism could be provided to do the unwind, just
that if there was one, would the strategy above be feasible? Also, do
some platforms already provide a way to unwind a stack? Is it possible
to provide one?
 
T

tonytech08

Huh?  Stack unwinding is the exact opposite of a function call.  How
would you call a function that unwound the stack?

Visual C++ provides the RtlUnwind() function (and 3 others also). I
think they may be for Structured Exception Handling though. Something
to read up on though for sure.
 
I

Ian Collins

tonytech08 said:
Scenario: An n-deep nesting of RAII contructors and an error occurs at
level n.

One doesn't need the C++ exception machinery to handle the error: an
installable handler (for example, set_new_handler()) can be used to
handle the error. If the error cannot be corrected ("handled") by any
installed handler (perhaps there is a hierarchy of installed
handlers), the stack needs to be unwound (destructors called) on all
the constructed RAII objects. An Unwind() function that would enable
installable handlers to be used in place of C++ exceptions seems to be
curiously missing.

Is the alternative to exceptions described above feasible if there was
an Unwind() function provided by the standard or the platform?

Why bother?
 
M

Maxim Yegorushkin

Scenario: An n-deep nesting of RAII contructors and an error occurs at
level n.

One doesn't need the C++ exception machinery to handle the error: an
installable handler (for example, set_new_handler()) can be used to
handle the error. If the error cannot be corrected ("handled") by any
installed handler (perhaps there is a hierarchy of installed
handlers), the stack needs to be unwound (destructors called) on all
the constructed RAII objects. An Unwind() function that would enable
installable handlers to be used in place of C++ exceptions seems to be
curiously missing.

Is the alternative to exceptions described above feasible if there was
an Unwind() function provided by the standard or the platform?

Why would you want such a thing?

Symbian created their own exception machinery for C++, similar to what
you describe. It is based on longjmp. As longjmp does not do stack
unwinding, one can't have stack objects with non-trivial destructors.
Objects with non-trivial destructors must be created on the heap and
their destructors must be manually registered in the clean-up stack.
This made Symbian C++ incompatible with standard C++. Programming
Symbian C++ is real pain for this reason. In my not so humble opinion,
they would have been much better off using plain C.

http://en.wikipedia.org/wiki/Symbian#Developing_on_Symbian_OS

No wonder Symbian OS sucks badly and now Nokia is trying to compete
with "real" operating systems like Android by making it open source.
Don't think any C++ developer would be interested in Symbian C++
atrocities.
 
T

tonytech08

Why bother?

The ongoing quest for blackbox avoidance and simplicity and complete
control. VC++ apparently has unwind functions but I haven't played
around with them yet.
 
T

tonytech08

Why would you want such a thing?

The ongoing quest for blackbox avoidance and simplicity and complete
control. VC++ apparently has unwind functions but I haven't played
around with them yet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top