#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
void exception_handling(int x)
{
try
{
if(x==1)
throw x;
else if(x==0)
throw 'x';
else
throw 1.09;
}
catch (char c)
{
cout<<"caught a character"<<endl;
}
catch(int m)
{
cout<<"caught an integer"<<endl;
}
catch(double d)
{
cout<<"caught a double value"<<endl;
}
}
int main()
{
cout<<"testing multiple characters"<<endl;
cout<<"x==1"<<endl;
exception_handling(1);
cout<<"x==0"<<endl;
exception_handling(0);
cout<<"x==anything else"<<endl;
exception_handling(rand());
getch();
return 0;
}
No comments:
Post a Comment