Program to illustrate the throwing and catching of an exception.
#include<iostream>
#define DivisionByZero 1
using namespace std;
int main()
{
int x=5,y=0;
try
{
if(y==0)
{throw DivisionByZero;}
int z=x/y;
}
catch (int exception_number)
{
if (exception_number==DivisionByZero)
{cout<<"Division By Zero is not allowed!!"<<endl;}
}
cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
}
Output:
#define DivisionByZero 1
using namespace std;
int main()
{
int x=5,y=0;
try
{
if(y==0)
{throw DivisionByZero;}
int z=x/y;
}
catch (int exception_number)
{
if (exception_number==DivisionByZero)
{cout<<"Division By Zero is not allowed!!"<<endl;}
}
cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
}
Output:
Comments
Post a Comment