-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path88.cpp
50 lines (44 loc) · 878 Bytes
/
88.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
#include<iostream>
#include<cstring>
using namespace std;
//definning a class of
class MyException
{
public:
char str[80];
int num;
//constructor
MyException()
{
*str=0;
num=0;
}
//parameterized constructor
MyException(char *s,int n)
{
strcpy(str,s);
num=n;
}
};
int main()
{
try
{
int n;
//input a positive number
cout<<"Enter a positive number : ";
cin>>n;
if(n<0)
{
//an object of MyException class is been thrown if entered number is smaller than 0
throw MyException("Not positive",n);
}
cout<<"Positive number : "<<n<<endl;
}
catch(MyException e)
{
cout<<e.str<<endl;
cout<<e.num<<endl;
}
return 0;
}