-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA15-5-2.cpp
More file actions
65 lines (53 loc) · 961 Bytes
/
A15-5-2.cpp
File metadata and controls
65 lines (53 loc) · 961 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
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
// Rule: A15-5-2
// Source line: 26939
// Original file: A15-5-2.cpp
//% $Id: A15-5-2.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <cstdlib>
#include <exception>
void F1() noexcept(false);
void F2() // Non-compliant
{
F1(); // A call to throwing f1() may result in an implicit call to
// std::terminate()
}
void F3() // Compliant
{
try
{
F1(); // Handles all exceptions from f1() and does not re-throw
}
catch (...)
{
// Handle an exception
}
}
void F4(const char* log)
{
// Report a log error
// ...
std::exit(0); // Call std::exit() function which safely cleans up resources
}
void F5() // Compliant by exception
{
try
{
F1();
}
catch (...)
{
F4("f1() function failed");
}
}
int main(int, char**)
{
if (std::atexit(&F2) != 0)
{
// Handle an error
}
if (std::atexit(&F3) != 0)
{
// Handle an error
}
// ...
return 0;
}