-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexception9.cpp
More file actions
37 lines (35 loc) · 776 Bytes
/
Copy pathexception9.cpp
File metadata and controls
37 lines (35 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//!Develop a function to throw a DivisionByZero exc0eption()
//Wap to write try catch throw to handle exception
//wap to handle ArrayOutOfBound exception
#include<iostream>
#include <ostream>
using namespace std;
char s[]={"ZeroByDivisionError"};
int Division(int a,int b)
{
try
{
if(b<0)
throw s;
else
{
return a/b;
}
}
catch(char s[])
{
cout<<"Caught exception : "<<s<<endl;
cout<<"because b is less than Zero\n"<<b<<endl;
exit(0);
}
}
int main()
{
int number1,number2;
cout<<"Enter the value of Number1 : ";
cin>>number1;
cout<<"Enter the value of Number2 : ";
cin>>number2;
cout<<"Result = "<<Division(number1, number2)<<endl;
return 0;
}