Topic: Questions about unexpected()
Author: smeyers@netcom.com (Scott Meyers)
Date: Fri, 1 Apr 1994 05:49:45 GMT Raw View
Dave Reed's article in the March C++ Report has a footnote indicating
that the current draft standard makes it illegal for the unexpected()
function to return. Does throwing an exception count as "return"ing?
If so, does this mean the pass-through strategy described in ARM
15.6.2 is no longer legal?
On a different note, when exactly does unexpected() get called? ARM
15.6.2 says it's called when "a function with an exception
specification throws an exception," but what if F calls G and G throws
an exception not in F's exception specification? When exactly is
unexpected called? I can think of three possibilities:
1. Immediately, i.e., F and G remain on the stack and unexpected is
added to the stack on top of G.
2. After removing G from the stack, i.e., F remains on the stack
and unexpected is added on top of it.
3. After removing both F and G from the stack, i.e., F and G are
both removed from the stack, and unexpected is put on the stack
on top of F's caller.
Note that in this example, F doesn't really throw an exception at all.
Rather, a function called by F does the throw.
Thanks for any clarifications,
Scott
Author: bobzim@interaccess.com (Bob Zimmerman)
Date: 1 Apr 1994 14:11:29 GMT Raw View
Scott Meyers (smeyers@netcom.com) wrote:
: Dave Reed's article in the March C++ Report has a footnote indicating
: that the current draft standard makes it illegal for the unexpected()
: function to return. Does throwing an exception count as "return"ing?
: If so, does this mean the pass-through strategy described in ARM
: 15.6.2 is no longer legal?
Actually, I have been using an exception as a "return" if you will. It
returns to the calling function if an exception condition occurs which
might invalidate my object. This doesn't necessarily mean a "hard
exception"... but, for example, in my database layer, if I add a record
which causes a duplicate key condition, I will throw an exception for
this... The caller then can handle this condition (catch it) or not...
: On a different note, when exactly does unexpected() get called? ARM
: 15.6.2 says it's called when "a function with an exception
: specification throws an exception," but what if F calls G and G throws
: an exception not in F's exception specification? When exactly is
: unexpected called? I can think of three possibilities:
: 1. Immediately, i.e., F and G remain on the stack and unexpected is
: added to the stack on top of G.
: 2. After removing G from the stack, i.e., F remains on the stack
: and unexpected is added on top of it.
: 3. After removing both F and G from the stack, i.e., F and G are
: both removed from the stack, and unexpected is put on the stack
: on top of F's caller.
: Note that in this example, F doesn't really throw an exception at all.
: Rather, a function called by F does the throw.
I am not sure when the unexpected actually gets called (or what the ARM
actually meant... BUT, my person opinion is that the stack unwinds
(normally) until that function which had the signature fails the "edit"
if you will... Then, the unexpected is added to the stack...
--
---------------------------------------------------
| If you think I am crazy... |
| Why are you reading my messages ???? |
---------------------------------------------------