-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path85.cpp
34 lines (33 loc) · 1007 Bytes
/
85.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
#include<iostream>
using namespace std;
//An exception can be thrown from outside the try block as long it is thrown by a function that is called from within try block.
void myFunc(int i)
{
cout<<"Inside the myfunc function() : "<<i<<endl;
if(i==0)
throw i; //an exception is been thrown if i==0
}
int main()
{
try
{
cout<<"Inside the try block"<<endl;
//calling myFunc()
myFunc(98);
myFunc(7);
myFunc(0);
myFunc(73);
}
catch(double d) //this catch block is entered only when thrown exception is of double type
{
cout<<"Inside the catch block which handles exception of double type"<<endl;
cout<<d<<endl;
}
catch(int i) //this catch block is entered only when thrown exception is of integer type.
{
cout<<"Inside the catch block which handles exception of integer type"<<endl;
cout<<i<<endl;
}
cout<<"Outside the try-catch block"<<endl;
return 0;
}