-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA15-2-1.cpp
More file actions
72 lines (51 loc) · 1.02 KB
/
A15-2-1.cpp
File metadata and controls
72 lines (51 loc) · 1.02 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Rule: A15-2-1
// Source line: 24301
// Original file: A15-2-1.cpp
//% $Id: A15-2-1.cpp 271927 2017-03-24 12:01:35Z piotr.tanski $
#include <cstdint>
#include <stdexcept>
class A
{
public:
A() noexcept : x(0)
{
// ...
}
explicit A(std::int32_t n) : x(n)
{
// ...
throw std::runtime_error("Unexpected error");
}
A(std::int32_t i, std::int32_t j) noexcept : x(i + j)
{
try
{
// ...
throw std::runtime_error("Error");
// ...
}
catch (std::exception& e)
{}
}
private:
std::int32_t x;
};
static A a1;
static A a2(5);
// Compliant - default constructor of type A is noexcept
// Non-compliant - constructor of type A throws, and the
// exception will not be caught by the handler in main function
static A a3(5, 10); // Compliant - constructor of type A is noexcept, it
// handles exceptions internally
int main(int, char**)
{
try
{
// program code
}
catch (...)
{
// Handle exceptions
}
return 0;
}