GCC Code Coverage Report


.
File: main.cpp
Date: 2025-09-27 21:24:05+00:00
Lines:
21 of 24, 0 excluded
87.5%
Functions:
6 of 6, 0 excluded
100.0%
Branches:
8 of 16, 0 excluded
50.0%
Conditions:
2 of 2, 0 excluded
100.0%
Calls:
11 of 16, 0 excluded
68.8%

Line Branch Condition Call Exec Source Block IDs
1 #include <stdexcept>
2
3 3 int function_that_may_throw(bool die) {
4
2/2
✓ Branch 2 → 3 taken 1 time.
✓ Branch 2 → 6 taken 2 times.
2/2
✓ Fully covered.
3 if (die) { [2]
5
1/2
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 8 not taken.
2/4
✓ Call 0 invoked.
✓ Call 1 invoked.
✗ Call 2 not invoked.
✗ Call 3 not invoked.
1 throw std::runtime_error("the error"); [3, 4, 5, 8]
6 } else {
7 2 return 42; [6, 7]
8 }
9 }
10
11 struct RAII {
12 bool die;
13
14 RAII(bool);
15 ~RAII();
16 1 int method_that_may_throw() const {
17
1/1
✓ Call 0 invoked.
1 return function_that_may_throw(die); [2, 3]
18 }
19 };
20
21 1 RAII::RAII(bool die) :die(die) {}
22 1 RAII::~RAII() {}
23
24 1 int function_with_catchers(int argc) {
25 1 bool die_again = true;
26
27 try {
28
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 10 taken 1 time.
1/1
✓ Call 0 invoked.
1 function_that_may_throw(argc == 1); [2]
29
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 1 time.
1/1
✓ Call 0 invoked.
1 } catch (std::exception&) { [10, 12]
30 1 die_again = false;
31
1/1
✓ Call 0 invoked.
1 } [13]
32
33
1/2
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 20 not taken.
1/1
✓ Call 0 invoked.
1 RAII raii(die_again); [3]
34
35 try {
36
1/2
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 14 not taken.
1/1
✓ Call 0 invoked.
1 raii.method_that_may_throw(); [4]
37
0/1
✗ Call 0 not invoked.
} catch (std::exception&) { [14, 16]
38 return 1;
39
0/1
✗ Call 0 not invoked.
} [17]
40
41
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 18 not taken.
1/1
✓ Call 0 invoked.
1 function_that_may_throw(argc != 1); [5]
42
43 1 return 0; [6]
44
1/2
✓ Call 0 invoked.
✗ Call 1 not invoked.
1 } [7, 18]
45
46
47 1 int main(int argc, char* argv[]) {
48
1/1
✓ Call 0 invoked.
1 return function_with_catchers(argc); [2, 3]
49 }
50