-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path66Exception_Handling.cpp
More file actions
58 lines (54 loc) · 1.07 KB
/
66Exception_Handling.cpp
File metadata and controls
58 lines (54 loc) · 1.07 KB
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
54
55
56
57
58
#include <iostream>
#include <exception>
#include <string>
#include <stdexcept>
#include <vector>
#include <cmath>
using namespace std;
class Server {
private:
public:
static int load;
static int compute(long long A, long long B) {
load += 1;
if(A < 0) {
throw ("A is negative");
}
vector<int> v(A, 0);
int real = -1, cmplx = sqrt(-1);
if(B == 0) throw 0;
real = (A/B)*real;
int ans = v.at(B);
return real + A - B*ans;
}
static int getLoad() {
return load;
}
};
int Server::load = 0;
int main() {
int T;
cout<<"Enter the value: "<<endl;
cin >> T;
while(T--) {
long long A, B;
cout<<"Enter the valur of A and B: "<<endl;
cin >> A >> B;
try {
if (A>= pow(2,4) || B>= pow(2,4)) {
cout<<"Not enough memory"<<endl;
Server::load+=1;
break;
}
cout<<Server::compute(A, B)<<endl;
}
catch (const char *e) {
cout<<"Exception: "<<e<<endl;
}
catch(...){
cout<<"Other exception"<<endl;
}
}
cout << Server::getLoad() << endl;
return 0;
}