25 Nov 2019

  • November 25, 2019
  • Amitraj
C++ Program to demonstrate Multiple catch statements

#include<iostream>
using namespace std;
void test(int x)
{
try
{
if(x==1) throw x;
else
    if(x==0) throw 'x';
else
    if(x==-1) throw 1.0;
  cout<<"End of try block\n";
}
catch(char c)
{
cout<<"Caught a character\n";
}
    
catch(int m)
{
cout<<"Caught a integer\n";
}

catch(double d)
{
cout<<"Caught a double\n";
}
cout<<"End of try catch\n";
}
int main()
{
test(1);
test(0);
test(-1);
test(2);
return 0;

}

 OUTPUT:

Caught a integer
End of try catch
Caught a character
End of try catch
Caught a double
End of try catch
End of try block

End of try catch

Translate

Popular Posts