MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / main

Function main

Examples/NoModules/Chapter 16/Ex16_06/Ex16_06.cpp:6–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "Troubles.h"
5
6int main()
7{
8 for (int i {}; i < 7; ++i)
9 {
10 try
11 {
12 try
13 {
14 if (i == 3)
15 throw Trouble{};
16 else if (i == 5)
17 throw MoreTrouble{};
18 else if (i == 6)
19 throw BigTrouble{};
20 }
21 catch (const BigTrouble& bt)
22 {
23 std::cout << "Oh dear, big trouble. Let's handle it here and now." << std::endl;
24 // Do not rethrow...
25 }
26 catch (...) // Catch any other exception
27 {
28 std::cout << "We caught something else! Let's rethrow it. " << std::endl;
29 throw; // Rethrow current exception
30 }
31 }
32 catch (const Trouble& t)
33 {
34 std::cout << typeid(t).name() << " object caught in outer block: "
35 << t.what() << std::endl;
36 }
37 std::cout << "End of the for loop (after the catch blocks) - i is " << i << std::endl;
38 }
39}

Callers

nothing calls this directly

Calls 1

whatMethod · 0.45

Tested by

no test coverage detected