The C++ exception handling: domain_error exception and typeid()
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info:
To do: Throw the domain_error exception and catching the typeid
To show: The domain_error exception and typeid() usage in C++ program sample
// domain_error and typeid()
#include <iostream>
using namespace std;
int main(void)
{
try
{
throw domain_error("Some error with your domain!");
}
catch (exception &err)
{
cerr<<"Caught: "<<err.what()<<endl;
cerr<<"Type: "<<typeid(err).name()<<endl;
};
}
Output example:
Caught: Some error with your domain!
Type: class std::domain_error
Press any key to continue . . .