Topic: Exceptionally cute?
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1997/09/25 Raw View
"Paul D. DeRocco" <pderocco@ix.netcom.crud.com> writes:
|> http://www.sigs.com/publications/docs/cppr/9607/cppr9607.c.reeves.html
|> has an article from C++ Report from Jack W. Reeves called "Ten
|> Guidelines for Exception Specification." In it, he gives the following
|> example for how to decode the type of an unexpected exception inside the
|> parameterless unexpected_handler.
|>
|> void my_unexpected_handler()
|> try {
|> throw; // rethrow the exception
|> }
|> catch (xalloc& ex) {
|> throw bad_alloc(); //or throw bad_exception();
|> }
|> catch (...) {
|> // throw bad_exception; or terminate();
|> }
|>
|> Is this really legal? Intuitively, it would seem to me that inside the
|> try block, a fresh exception environment is established, so there is no
|> unhandled exception that can be rethrown--that only exists outside the
|> try block. Can the language lawyers in residence shed any light on this?
I don't think it's illegal. The relevant text (section 15.1/6): "The
exception thrown is the one most recently caught and not finished. An
exception is considered caught when initialization is complete for the
formal parameter of the corresponding catch clause, or when terminate()
or unexpected() is entered due to a throw. An exception is considered
finished when the corresponding catch clause exits or when unexpected()
exits after being entered due to a throw." Note that the definitions of
"caught" and "finish" refer to instances of program execution, and not
lexical structures. And that an exception is definitly rethrowable from
within unexpected.
--
James Kanze +33 (0)1 39 23 84 71 mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
I'm looking for a job -- Je recherche du travail
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/09/26 Raw View
"Paul D. DeRocco" <pderocco@ix.netcom.crud.com> writes:
>http://www.sigs.com/publications/docs/cppr/9607/cppr9607.c.reeves.html
>has an article from C++ Report from Jack W. Reeves called "Ten
>Guidelines for Exception Specification." In it, he gives the following
>example for how to decode the type of an unexpected exception inside the
>parameterless unexpected_handler.
>
> void my_unexpected_handler()
> try {
> throw; // rethrow the exception
> }
> catch (xalloc& ex) {
> throw bad_alloc(); //or throw bad_exception();
> }
> catch (...) {
> // throw bad_exception; or terminate();
> }
>
>Is this really legal?
Yes.
>Intuitively, it would seem to me that inside the
>try block, a fresh exception environment is established, so there is no
>unhandled exception that can be rethrown--that only exists outside the
>try block. Can the language lawyers in residence shed any light on this?
I'm afraid your intuition is wrong. 15.1 [except.throw] paragraph 6 is
IMHO quite clear about the behaviour of `throw' with no argument --
it is the one most recently caught and whose handler has not yet finished.
Entrying a `try' block does not change the effect that `throw' will have.
Also 15.5.2 [expect.unexpected] makes it clear that an unexpected()
handler function is allowed to rethrow the exception.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "Paul D. DeRocco" <pderocco@ix.netcom.crud.com>
Date: 1997/09/23 Raw View
http://www.sigs.com/publications/docs/cppr/9607/cppr9607.c.reeves.html
has an article from C++ Report from Jack W. Reeves called "Ten
Guidelines for Exception Specification." In it, he gives the following
example for how to decode the type of an unexpected exception inside the
parameterless unexpected_handler.
void my_unexpected_handler()
try {
throw; // rethrow the exception
}
catch (xalloc& ex) {
throw bad_alloc(); //or throw bad_exception();
}
catch (...) {
// throw bad_exception; or terminate();
}
Is this really legal? Intuitively, it would seem to me that inside the
try block, a fresh exception environment is established, so there is no
unhandled exception that can be rethrown--that only exists outside the
try block. Can the language lawyers in residence shed any light on this?
--
Ciao,
Paul
(Please remove the extra "crud" from the return address,
which has been altered to foil junk mail senders.)
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]