The try-catch-throw - mismatch type C++ program example with source code


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: Catching a type in try-catch-throw C++ program example

To show: The try-catch-throw - mismatch type




// Mismatch type, throw integer type, catch the double type...

#include <iostream>

using namespace std;

void Funct();

int main(void)








cerr<<"caught a double type..."<<endl;


return 0;


void Funct()


// Change this to integer, rebuild and re-run this program

throw 3.1234;



Output example:


caught a double type...

Press any key to continue . . .


Change the following code:


throw 3.1234; to throw 3;


Rebuild and re-run the program. The Debug Error (Abort, Retry, Ignore) message box should be expected.



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