-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception.cpp
More file actions
36 lines (33 loc) · 776 Bytes
/
exception.cpp
File metadata and controls
36 lines (33 loc) · 776 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
#include <iostream>
#include <string>
using namespace std;
int main() {
int i;
int ax[5] = {10, 20, 60, 40, 30};
cout << "Enter Index: ";
cin >> i;
try{
if(i < 0 || i >= 5) {
if(i < 0) {
throw i;
}
else if (i >= 5 && i <= 10){
throw string("Out of Range Error");
}
else{
throw;
}
}
cout << "ax[" << i << "] = " << ax[i] << endl;
}
catch(int x){
cout << "Exception caught: Invalid index value = " << x << endl;
}
catch(string s){
cout << "Exception caught: " << s << endl;
}
catch(...){
cout << "Exception caught: Unknown error!" << endl;
}
return 0;
}