-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexception1.cpp
More file actions
51 lines (43 loc) · 896 Bytes
/
Copy pathexception1.cpp
File metadata and controls
51 lines (43 loc) · 896 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
39
40
41
42
43
44
45
46
47
48
49
50
51
//*Exception Handling
/*
try
{
code that might throw an exception
}
catch (exception_type arg)
{
code to handle the exception
}
throw exception;
*/
/*
C++ exception handling is done using 3 key words
--> Try
--> Catch
--> Throw
1.The program statements that has to be monitered for exceptions or errors
are written inside the "Try" block
2.If an exception occurs within "Try" block it is thrown
using the keyword "Throw"
3.The exception is caught using the keyword "catch" and then processed
*/
#include<iostream>
using namespace std;
int main()
{
cout<<"Start\n";
try
{
cout<<"Inside try block\n";
throw 100;
cout<<"This will not be executed/printed\n";
}
//catch(double i) try it(abnormal termination)
catch(int i)
{
cout<<"Caught exception: "<<endl;
cout<<i<<"\n";
}
cout<<"end\n";
return 0;
}