By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,501 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,501 IT Pros & Developers. It's quick & easy.

type info of exception

P: n/a
Is it possible to portably get the typename of an exception
that occurred?

I noticed when an uncaught exception occurred, GCC (3.4.1)
displayed:

terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid

So I tried:

catch(std::exception &e) {
std::cerr << "[E] Exception (" << typeid(e).name()
<< ") thrown: " << e.what() << std::endl;
}
but got output:
[E] Exception (St11logic_error) thrown:
basic_string::_S_construct NULL not valid

ie. it said St11logic_error instead of std::logic_error. Do
I have to try using a compiler-specific unmangling function?
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Old Wolf" wrote:
that occurred?

I noticed when an uncaught exception occurred, GCC (3.4.1)
displayed:

terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid

So I tried:

catch(std::exception &e) {
std::cerr << "[E] Exception (" << typeid(e).name()
<< ") thrown: " << e.what() << std::endl;
}
but got output:
[E] Exception (St11logic_error) thrown:
basic_string::_S_construct NULL not valid

ie. it said St11logic_error instead of std::logic_error. Do
I have to try using a compiler-specific unmangling function?


In the C++ standard, under 18.5.1[8], the return of
std::type_info::name() is
implementation-defined. This means that some compilers might chose to
return
"std::logic_error", some might have some specific mangled name for it
(such as
it is in your case) or some might even return an empty string.

Vladimir Ciobanu
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.