The range_error C++ exception program example


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: Try and catch construct catching the range_error C++ exception

To show: The range_error exception in C++ programming





// range_error

#include <iostream>

using namespace std;


int main(void)




throw range_error("Some error in the range!");


catch(exception &Test)


cerr<<"Caught: "<<Test.what()<<endl;

cerr<<"Type: "<<typeid(Test).name()<<endl;




Output example:


Caught: Some error in the range!

Type: class std::range_error

Press any key to continue . . .



C and C++ Programming Resources | C & C++ Code Example Index