Topic: nested exceptions
Author: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Date: 1998/06/28 Raw View
Alexander Krotoff wrote:
>
> Both GNU and EDG-based compilers do terminate() call
> in the following example. MSVC handles both exceptions.
> Who is right ?
>
> void f()
> {
> throw 1;
> }
>
> int main ()
> {
> try {
> f();
> } catch (int x) {
> try {
> f();
> } catch (int x) {
> }
> }
> }
There's nothing wrong with this code. It should work fine. Consider this
simple case:
try {
// ...
}
catch (const exception& e) {
some_other_func();
}
If your example was problematic, then mine would be too, if it turned
out that some_other_func used exceptions (that is, threw, caught and
completely handled) internally. Since that would obviously be bogus, C++
must allow nested exceptions. If after the inner catch block, you do a
"throw;", it should rethrow the original exception, since you're still
inside the outer catch block.
--
Ciao,
Paul
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Alexander Krotoff <krotoff@such.srcc.msu.su>
Date: 1998/06/25 Raw View
Hi,
In the Dec96 WP it is not explicitly stated: is it
legal to throw an exception while another exception is
caught but not finished (see 15.1 p5).
Both GNU and EDG-based compilers do terminate() call
in the following example. MSVC handles both exceptions.
Who is right ?
void f()
{
throw 1;
}
int main ()
{
try {
f();
} catch (int x) {
try {
f();
} catch (int x) {
}
}
}
Regards,
Alexander
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Alexander Krotoff <krotoff@such.srcc.msu.su>
Date: 1998/06/27 Raw View
In article <199806251312.RAA01800@such.srcc.msu.su> Alexander Krotoff wrote:
AK> In the Dec96 WP it is not explicitly stated: is it
AK> legal to throw an exception while another exception is
AK> caught but not finished (see 15.1 p5).
AK> Both GNU and EDG-based compilers do terminate() call
AK> in the following example. MSVC handles both exceptions.
AK> Who is right ?
Sorry, I was wrong about GNU and EDG.
-ank
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Mungo Henning <mungoh@itacs.strath.ac.uk>
Date: 1998/06/27 Raw View
Alexander Krotoff wrote:
> In the Dec96 WP it is not explicitly stated: is it
> legal to throw an exception while another exception is
> caught but not finished (see 15.1 p5).
Hmmm... "legal" meaning is it allowed to occur (yes), but if it happens
then terminate() is always called. The scenario painted is one where an
exception is thrown and we then start to destroy intermediate objects
as we unwind the stack. What happens when one of those destructors
(which are called via the exception processing code written by the
compiler) also throw an exception? This is the documented
exception-whilst-processing-an-exception scenario as far as I know.
When execution gets inside the open curly bracket which I've commented
as "mark Z" in your code below, the exception is deemed handled (it had
been thrown, but now its flight is over since it is now caught). When
the internal code within this catch throws an exception, this is a
separate issue, therefore there is a second independent throw. Inside
the "catch" block you can re-throw the original exception via the
command "throw;", which is a move from a no-exceptions-thrown state to
an exception-has-been-thrown state.
Hope this is of use (also, hope I'm right! :-)
Mungo Henning
> int main ()
> {
> try {
> f();
> } catch (int x) { // <-- mark Z
> try {
> f();
> } catch (int x) {
> }
> }
> }
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]