c++ - terminate called after throwing an instance of 'std::string' -
i have binary thats crashing throwing exception of type std:string.
stack trace stripped binary:
terminate called after throwing instance of 'std::string' *** aborted @ 1309483487 (unix time) try "date -d @1309483487" if using gnu date *** pc: @ 0x3fb0c30155 (unknown) *** sigabrt (@0xd54) received pid 3412 (tid 0x40d03940) pid 3412; stack trace: *** @ 0x3fb180de70 (unknown) @ 0x3fb0c30155 (unknown) @ 0x3fb0c31bf0 (unknown) @ 0x2aaaaab80cc4 (unknown) @ 0x2aaaaab7ee36 (unknown) @ 0x2aaaaab7ee63 (unknown) @ 0x2aaaaab7ef4a (unknown) @ 0x4c2622 xyz::connect() @ 0x4c3e0f xyz::refresh() @ 0x3fb18062f7 (unknown) @ 0x3fb0cd1e3d (unknown)
now thing is, refresh() function try catch std::string. looks like:-
bool xyz::refresh() { try { connect(); } catch (string& s) { return false; } return true; }
any idea why not getting caught? or reading stack trace wrong?
perhaps or modules compiled -fno-exceptions
? see http://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html details on how changes exception behavior.
for example, following short program displays "terminate called after throwing instance of 'std::string'"
if:
- the module contains
foo()
compiled-fno-exceptions
, and foo()
calls throws exception of typestd::string
(all other modules compiled-fexceptions
)#include <string> #include <iostream> using namespace std; int foo(); int main() { try { foo(); } catch (string& s) { std::cout << "caught it: \"" << s << "\"" << endl; } return 0; }
note if recompile foo.cpp
-fexceptions (g++'s default) , relink, program displays:
caught it: "the string exception"
as expected.
or perhaps intermediate function had throw specification didn't list std::string
?
for example, program:
#include <string> #include <iostream> using namespace std; int hunc() throw(int); // can throw int (?) int main() { try { hunc(); } catch (string& s) { std::cout << "caught it: \"" << s << "\"" << endl; } return 0; } int hunc() throw(int) { throw string("the string exception"); }
also displays "terminate called after throwing instance of 'std::string'". both examples tested on windows box mingw 4.5.1.
Comments
Post a Comment