-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathNestedTry-Catch.cpp
53 lines (30 loc) · 904 Bytes
/
NestedTry-Catch.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
50
51
52
53
#include<iostream>
#include<stdexcept>
using namespace std;
//Program to show Nested try-catch blocks and re-throwing exceptions
int main()
{
try {
//throw("Char error occured");-if in parent try block we throw something , then the child try block is not executed
try
{
throw ("Character error occured");
}
catch(const char *err)
{
cout<<err<<endl;
cout<<"Rethrowing the runtime exception :-"<<endl;
//re-throwing another type of exception
//only the first re-defined throwed exception is catched not throwed after that
throw runtime_error("Runtime exception occured");
throw ("Rethrowing char exception");//not caught
}
}
catch(const char *err) {
cout<<"Outer character exception-->"<<err<<endl;
}
catch(runtime_error &err) {
cout<<"outer runtime exception error-->"<<err.what()<<endl;
}
return 0;
}