i was dealing with the following code,& got confused,please have a look at it
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
void Xhandler(int test) throw(char,double) /*i am restricting an integer exception here by not including it in the argument list of throw*/
{
if(test==0) throw test;
if(test==1) throw 'a';
if(test==2) throw 123.23;
}
int main()
{
cout<"start";
try{
Xhandler(0);
}
catch(int i) /*this catch statement must be ignored then,but it is running*/
{
cout<<"caught an integer"; /*this is the output on the screen*/
}
catch(char c)
{
cout<<"caught character";
}
catch(double a)
{
cout<<"caught double";
}
cout<<"end";
_getch();
return 0;
}
the catch statement corresponding to int must be ignored(which is not ignored) & program must have to be terminated as there is no matching catch statement left,but it is not so?
You did not specified the compiler. If you are using Microsoft visual C++ there is a note at Exception Specifications page on the MSDN
When using g++ the process is terminated due unexpected exception when running your example.