-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA15-4-2.cpp
More file actions
39 lines (38 loc) · 838 Bytes
/
A15-4-2.cpp
File metadata and controls
39 lines (38 loc) · 838 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
// Rule: A15-4-2
// Source line: 25864
// Original file: A15-4-2.cpp
//% $Id: A15-4-2.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <stdexcept>
// library.h
void LibraryFunc();
// project.cpp
void F1() noexcept
{
// ...
throw std::runtime_error("Error"); // Non-compliant - f1 declared to be
// noexcept, but exits with exception.
// This leads to std::terminate() call
}
void F2() noexcept(true)
{
try
{
// ...
throw std::runtime_error(
"Error"); // Compliant - exception will not leave f2
}
catch (std::runtime_error& e)
{
// Handle runtime error
}
}
void F3() noexcept(false)
{
// ...
throw std::runtime_error("Error"); // Compliant
}
void F4() noexcept(
false) // Compliant - no information whether library_func() throws or not
{
LibraryFunc();
}