> From:
chrisn@valvesoftware.com (Chris Newcombe)[color=blue]
> Thanks -- yes I'm already using it and it appears to work. However
> given the apparent ambuiguity of the standard I'd really like to get
> an authoratative statement from the compiler developers that the code
> generated is correct in all cases (i.e. has no side effects, and isn't
> just acceidentally appearing to work).
>
> I do plan to ask on comp.std.c++ but any defect report or ambiguity
> resolution will be far too late to affect my current project. I
> really need to know asap if this technique is practically safe with
> the current VC++ 7.0 compiler.
>
> Is there a developer on this list who worked on exception handling?[/color]
I implemented the fix in the CRT to get this example working in VC++ 7.0,
back about 4 years ago. Under the current implementation, when a catch
block exits via normal fall-through, the exception object will be destroyed
except when the catch block is nested within some other catch block which
is using the same exception object.
Now as it turns out, Bill Wade submitted this as a defect report back in
Feb 2000 (see issue 208,
http://www.comeaucomputing.com/iso/c...ects.html#208). That DR has a
status of WP, which means that the standards committee has voted to apply
the issue to the current Working Paper. That is, this will be officially
fixed in the C++0x, but not in the current standard. I have no information
on just why that is.
As it stands, yes, you can count on VC++ 7.0 and beyond to act as you wish
here, since we went out of our way to make sure that was true. The earlier
implementation would just destroy the exception object when exiting a catch
block via fall-through, even when nested within another catch block.
Do note that this behavior is not guaranteed by the current C++ standard,
so it's not likely to be portable, as Carl Daniel stated.
...Phil (one-time VC++ CRT dev)
--
Phil Lucido, Microsoft Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm