Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Beginner
Jun 6, 2000

Exception.what() Gives Vague Description

Question:
I'm using a catch(exception e). When I come in the catch-block and print the message belonging to the exception, I receive the message "9exception." What does it mean?

Answer:
The exact textual description of C++ exception is compiler-dependent. The Standard requires that they be null-terminated C-strings, but nothing more. Therefore, you need to consult your compiler's manuals or online help to gather more information about the meaning of this particular exception description.

However, you can detect the exact type of your exception object using Runtime Type Information (RTTI). This is sufficient for most purposes:

catch(exception & e)
{
 cout << typeid(e).name(); // display the actual type of e
}
It's highly recommended to catch exceptions by reference (as in my example), rather than by value.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap