Re: Rationale behind unwind-protect and double errors
- From: George Neuner <gneuner2@xxxxxxxxxxx>
- Date: Mon, 19 Jan 2009 16:36:27 -0500
On Sun, 18 Jan 2009 14:40:36 +0000, Mark Wooding
<mdw@xxxxxxxxxxxxxxxx> wrote:
Barry Kelly <barry.j.kelly@xxxxxxxxx> writes:
Be careful what you bundle together there! C++ doesn't have a
try/finally exception handling system.
True. C++ programmers usually use destructors for the same purpose. I
don't think that matters much for the purposes of this discussion,
though the correction is appreciated.
Yes, some programmers try to use destructors, but destructor semantics
are different from try-finally (which C++ does not have). The
preferred idiom for emulating try-finally is to use a conditional
block after try-catch.
It's actually pretty easy to implement a decent try-finally in C++
using preprocessor macros. It isn't perfect because there are too
many ways to implement an exception (dynamically, on the stack, object
or primitive type, etc.) and the exception may need to be preserved
outside the catch block to be thrown again. But it's not hard if you
can pick an implementation and standardize your code base.
Moreover, C++ on Windows usually supports structured exception
handling (SEH), which does not use the mechanism you outline.
The mechanism I described matches the specification in the C++ standard
pretty well. If an implementation doesn't work that way, then it's
broken. Implementation extensions are another matter, but `Windows C++'
isn't the same as `C++'.
Windows SEH is completely independent of C++. It is part of the
Windows API and can be used from any language that can make system
calls.
I note that the C# language doesn't expose this richer exception-
handling semantics to programmers, despite the language's general
objective to provide an interface to the whole of the .NET platform.
..NET (like JVM) is severely lacking in control knobs. A number of
important things like threading, mutual exclusion, load file control,
etc. have only half-assed, lowest denominator implementations and make
your life miserable if you require behavior different from what is
provided.
That said, SEH is accessible from all .NET languages - but it doesn't
play particularly nicely with any of them.
George
.
- References:
- Rationale behind unwind-protect and double errors
- From: Ulrich Neumerkel
- Re: Rationale behind unwind-protect and double errors
- From: Kaz Kylheku
- Re: Rationale behind unwind-protect and double errors
- From: Ulrich Neumerkel
- Re: Rationale behind unwind-protect and double errors
- From: Mark Wooding
- Re: Rationale behind unwind-protect and double errors
- From: Barry Kelly
- Re: Rationale behind unwind-protect and double errors
- From: Mark Wooding
- Rationale behind unwind-protect and double errors
- Prev by Date: Re: Making Lisp popular - can it be done?
- Next by Date: Lisp on the JVM
- Previous by thread: Re: Rationale behind unwind-protect and double errors
- Next by thread: Re: Rationale behind unwind-protect and double errors
- Index(es):
Relevant Pages
|