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