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:

Comments

Popular posts from this blog

To implement the various components of HTML5 Canvas

Program to illustrate the concept of templates.

Program to illustrate the order of execution of constructors and destructors in inheritance.