forked from teseoch/CPP-Fall-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path45-multi_layer.cpp
64 lines (55 loc) · 1.05 KB
/
45-multi_layer.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
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <stdexcept>
int F(int x)
{
// try
// {
if (x > 10)
{
throw std::runtime_error{"Something bad happened."};
}
// }
// catch (std::runtime_error &e)
// {
// std::cout << "got it in f" << std::endl;
// }
return x * 10;
}
int G(int y)
{
int result{0};
// try
// {
try
{
while (y < 100)
{
result += F(y);
y = 2 * y;
}
}
catch (std::runtime_error &e)
{
std::cout << "got it in g" << std::endl;
// std::invalid_argument ex{"i dont know what to do"};
// throw ex;
throw std::invalid_argument{"i dont know what to do"};
}
catch (std::invalid_argument &e)
{
std::cout << "invalid argument" << std::endl;
}
// }
// catch (std::invalid_argument &e)
// {
// std::cout << "invalid argument" << std::endl;
// }
return result;
}
int main()
{
int y{999};
y = G(6);
std::cout << "y is " << y << std::endl;
return 0;
}