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 create an html page with frames and frameset

1. Write a program to insert a new element at end as well as at a given position in an array in Java

Write a menu driven program to perform insertion and deletion operations in a single linked list