jwatte:/tmp> cat foo.cpp
#include <stdexcept>
#include <stdio.h>
int main() {
try {
throw std::runtime_error("hello, world");
}
catch (std::exception &re) {
fprintf(stderr, "%s\n", re.what());
}
return 0;
}
jwatte:/tmp> g++ -o foo foo.cpp
jwatte:/tmp> ./foo
terminate called after throwing an instance of 'std::runtime_error'
terminate called recursively
Aborted
jwatte:/tmp> g++ -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ./configure --prefix=/usr
Thread model: posix
gcc version 4.2.0
Why?
Note that changing the catch to a std::runtime_error &, or const &, doesn't change the behavior. Even a ... doesn't help.
g++ 4.2.0 and throwing exceptions not catching
This shell transcript should pretty much tell the story:
enum Bool { True, False, FileNotFound };
I tested Ubuntu Gutsy's 4.2.1 rather than 4.2.0 without reproducing the problem. So, I'm unsure.
nav@seeker:/tmp$ cat foo.cpp#include <stdexcept>#include <stdio.h>int main() { try { throw std::runtime_error("hello, world"); } catch (std::exception &re) { fprintf(stderr, "%s\n", re.what()); } return 0;}nav@seeker:/tmp$ g++-4.2 -o foo foo.cpp nav@seeker:/tmp$ ./foo hello, worldnav@seeker:/tmp$ gcc-4.2 -vUsing built-in specs.Target: i486-linux-gnuConfigured with: ../src/configure -v--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr--enable-shared --with-system-zlib --libexecdir=/usr/lib--without-included-gettext --enable-threads=posix --enable-nls--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2--enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-targets=all--disable-werror --enable-checking=release --build=i486-linux-gnu--host=i486-linux-gnu --target=i486-linux-gnuThread model: posixgcc version 4.2.1 20070627 (prerelease) (Ubuntu 4.2-20070627-1ubuntu1)
It works fine on slackware, tested with gcc 4.1.1 and 4.3.0.
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
ice@SirGalahad:~/coding$ g++ except.cpp -o exceptice@SirGalahad:~/coding$ ./excepthello, worldice@SirGalahad:~/coding$ g++ -vUsing built-in specs.Target: x86_64-linux-gnuConfigured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release x86_64-linux-gnuThread model: posixgcc version 4.1.2 (Ubuntu 4.1.2-0ubuntu4)ice@SirGalahad:~/coding$
Dunno what your problem is...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement