devxlogo

Exception.what() Gives Vague Description

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.

See also  5 Benefits of Using Time Tracking Software
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist