-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path92.cpp
More file actions
39 lines (37 loc) · 814 Bytes
/
Copy path92.cpp
File metadata and controls
39 lines (37 loc) · 814 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
38
//restricting exceptions
#include<iostream>
using namespace std;
//this function can only throw ints, chars and doubles.
void myfunc(int i) throw (int,char,double)
{
if(i==0)
throw 1;
if(i==1)
throw 1.23;
if(i==2)
throw 'e';
}
//if this function attempts to throw any other type of exception, then an abnormal termination will occur. Remove int from the list and run the program.
int main()
{
cout<<"Beginning of the program"<<endl;
try
{
myfunc(0);
// myfunc(1);
// myfunc(2);
}
catch(int i)
{
cout<<"Caught an integer exception"<<endl;
}
catch(char c)
{
cout<<"Caught a char exception"<<endl;
}
catch(double d)
{
cout<<"Caught a double exception"<<endl;
}
return 0;
}