How is unexpected() defined?
Maurizio Loreti
loreti@pd.infn.it
Thu Nov 1 03:19:00 GMT 2001
Hello - the current standard states that, if a procedure declares the
exceptions that may be thrown and throws an exception not declared, the
procedure unexpected() is called; and that in turn unexpected() may
throw, or call terminate().
I was playing with the following toy code:
#include <iostream>
#include <stdexcept>
void fun() throw() {
std::cout << "In fun()\n";
throw std::runtime_error("ahi ahi");
}
int main() {
try{
fun();
} catch (std::exception &e) {
std::cout << "Exception: \"" << e.what() << "\"\n";
}
return 0;
}
namespace std {
void unexpected() {
cout << "In unexpected()\n";
throw;
}
};
Compiled and linked with KCC does what is expected, i.e.:
In fun()
In unexpected()
Exception: "ahi ahi"
Compiled and linked with g++ 3.0.2 it does not:
In fun()
Aborted (core dumped)
Looking at the core file with gdb:
MLO@mlinux 14 $ gdb ./foo core
GNU gdb 5.0
...
(gdb) where
#0 0x400b8d41 in __kill () from /lib/libc.so.6
#1 0x400b89b6 in raise (sig=6) at ../sysdeps/posix/raise.c:27
#2 0x400ba0d8 in abort () at ../sysdeps/generic/abort.c:88
#3 0x40045685 in _ZN10__cxxabiv111__terminateEPFvvE (
handler=0x400ba010 <abort>)
at ../../../../gcc-3.0.2/libstdc++-v3/libsupc++/eh_terminate.cc:47
#4 0x400456c0 in _ZN10__cxxabiv112__unexpectedEPFvvE (
handler=0x400456c0 <_ZN10__cxxabiv112__unexpectedEPFvvE>)
at ../../../../gcc-3.0.2/libstdc++-v3/libsupc++/eh_terminate.cc:57
#5 0x400456d5 in _ZN10__cxxabiv112__unexpectedEPFvvE (
handler=0x400456a0 <_ZSt9terminatev>)
at ../../../../gcc-3.0.2/libstdc++-v3/libsupc++/eh_terminate.cc:63
#6 0x4004558a in __cxa_call_unexpected (exc_obj=0x804f208)
at ../../../../gcc-3.0.2/libstdc++-v3/libsupc++/eh_personality.cc:417
#7 0x804a552 in _Z3funv ()
#8 0x804a56e in main ()
#9 0x400b29cb in __libc_start_main (main=0x804a560 <main>, argc=1,
argv=0xbffff9d4, init=0x804a044 <_init>, fini=0x804c970 <_fini>,
rtld_fini=0x4000ae60 <_dl_fini>, stack_end=0xbffff9cc)
at ../sysdeps/generic/libc-start.c:92
(gdb)
shows that something like unexpected is called
("_ZN10__cxxabiv112__unexpectedEPFvvE"), with a signature different
from my own unexpected(). Grepping the include files for 'unexpected'
shown nothing.
The questions are:
1) what g++ exactly does in these situations?
2) the g++ behavior is not standard, is it? If it were, *my*
unexpected had to be called.
3) what am I supposed to do (command line options, ...) in order to
force g++ to a standard behavior?
Thank you in advance, M.
--
Maurizio Loreti http://www.pd.infn.it/~loreti/mlo.html
Univ. of Padova, Dept. of Physics - Padova, Italy loreti@pd.infn.it
More information about the Libstdc++
mailing list