Topic: Verifying compiler bug (nested exceptions)
Author: "Richard Browne" <richb@pobox.com.au>
Date: 1999/08/28 Raw View
Would someone mind verifying for me that the following program should work.
With MSVC, the call to the virtual function in main()'s catch block jumps to
an invalid location. Thanks:
#include <iostream>
#include <exception>
#include <string>
struct my_exception : public std::exception {
virtual void blah();
};
void my_exception::blah() {
std::cerr << "my_exception::blah...\n";
}
void throw_an_exception2() {
throw my_exception();
}
void throw_an_exception()
{
try {
throw_an_exception2();
}
catch (...) {
try { // guard against exception during exception
std::string s;
try { // determine what throw_an_exception2 threw
throw;
}
catch (my_exception&) {
s = "It's a my_exception\n";
}
catch (...) {
s = "It's an unknown exception\n";
}
std::cerr << s;
}
catch (...) { }
throw;
}
}
void print_the_exception()
{
try {
throw;
}
catch (my_exception& e) {
e.blah();
}
catch (...) { }
}
int main(char argc, int* argv[])
{
try {
throw_an_exception();
}
catch (...) {
print_the_exception();
}
return 0;
}
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ 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: "Dave Abrahams" <abrahams@mediaone.net>
Date: 1999/08/28 Raw View
In article <935749650.859675@jaguarundi> , "Richard Browne"
<richb@pobox.com.au> wrote:
> Would someone mind verifying for me that the following program should work.
> With MSVC, the call to the virtual function in main()'s catch block jumps to
> an invalid location. Thanks:
This is a bug in MSVC 6 which has been reported to this newsgroup several
times in the last few months. Consider a different compiler for targeting
this platform. The Metrowerks compiler, for example, does a much better job
with correctness of exception-handling. Also, you will avoid the problems
that MSVC causes with catch(...) and post-mortem debugging.
-Dave
---
[ 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: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/08/28 Raw View
Richard Browne wrote:
> Would someone mind verifying for me that the following program should work.
> With MSVC, the call to the virtual function in main()'s catch block jumps to
> an invalid location.
I can't find any problems w/ your code.
egcs happily prints:
It's a my_exception
my_exception::blah...
--
Valentin Bonnard
[ 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 ]