{"pageProps":{"code":{"CMakeLists.txt":{"name":"CMakeLists.txt","content":"add_executable(by-ref by-ref.cpp)\r\n\r\nadd_executable(by-value by-value.cpp)\r\n\r\nadd_executable(exception1 exception1.cpp)\r\n\r\nadd_executable(exception2 exception2.cpp)\r\n\r\nadd_executable(multiple multiple.cpp)\r\n","path":"code/6771/24T2/5.1/CMakeLists.txt","fileext":"txt"},"by-ref.cpp":{"name":"by-ref.cpp","content":"#include <iostream>\r\n\r\nclass Giraffe {\r\npublic:\r\n    Giraffe() { std::cout << \"Giraffe constructed\" << '\\n'; }\r\n    Giraffe(const Giraffe& g) { (void) g; std::cout << \"Giraffe copy-constructed\" << '\\n'; }\r\n    ~Giraffe() { std::cout << \"Giraffe destructed\" << '\\n'; }\r\n};\r\n\r\nvoid zebra()\r\n{\r\n    throw Giraffe {};\r\n}\r\n\r\nvoid llama()\r\n{\r\n    try {\r\n        zebra();\r\n    } catch (const Giraffe& g) {\r\n        (void) g;\r\n        std::cout << \"caught in llama; rethrow\" << '\\n';\r\n        throw;\r\n    }\r\n}\r\n\r\nint main()\r\n{\r\n    try {\r\n        llama();\r\n    } catch (const Giraffe& g) {\r\n        (void) g;\r\n        std::cout << \"caught in main\" << '\\n';\r\n    }\r\n}","path":"code/6771/24T2/5.1/by-ref.cpp","fileext":"cpp"},"by-value.cpp":{"name":"by-value.cpp","content":"#include <iostream>\r\n\r\nclass Giraffe {\r\npublic:\r\n    Giraffe() { std::cout << \"Giraffe constructed\" << '\\n'; }\r\n    Giraffe(const Giraffe& g) { (void) g; std::cout << \"Giraffe copy-constructed\" << '\\n'; }\r\n    ~Giraffe() { std::cout << \"Giraffe destructed\" << '\\n'; }\r\n};\r\n\r\nvoid zebra()\r\n{\r\n    throw Giraffe {};\r\n}\r\n\r\nvoid llama()\r\n{\r\n    try {\r\n        zebra();\r\n    } catch (Giraffe g) {\r\n        (void) g;\r\n        std::cout << \"caught in llama; rethrow\" << '\\n';\r\n        throw;\r\n    }\r\n}\r\n\r\nint main()\r\n{\r\n    try {\r\n        llama();\r\n    } catch (Giraffe g) {\r\n        (void) g;\r\n        std::cout << \"caught in main\" << '\\n';\r\n    }\r\n}","path":"code/6771/24T2/5.1/by-value.cpp","fileext":"cpp"},"exception1.cpp":{"name":"exception1.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nauto main() -> int\r\n{\r\n    std::cout << \"Enter -1 to quit\\n\";\r\n    std::vector<int> items { 97, 84, 72, 65 };\r\n    std::cout << \"Enter an index: \";\r\n    for (int print_index; std::cin >> print_index;) {\r\n        if (print_index == -1)\r\n            break;\r\n        std::cout << items.at(static_cast<unsigned int>(print_index)) << '\\n';\r\n        std::cout << \"Enter an index: \";\r\n    }\r\n}","path":"code/6771/24T2/5.1/exception1.cpp","fileext":"cpp"},"exception2.cpp":{"name":"exception2.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nauto main() -> int\r\n{\r\n    std::cout << \"Enter -1 to quit\\n\";\r\n    std::vector<int> items { 97, 84, 72, 65 };\r\n    std::cout << \"Enter an index: \";\r\n    for (int print_index; std::cin >> print_index;) {\r\n        if (print_index == -1)\r\n            break;\r\n        try {\r\n            std::cout << items.at(static_cast<unsigned int>(print_index)) << '\\n';\r\n            items.resize(items.size() + 10);\r\n        } catch (const std::out_of_range& e) {\r\n            std::cout << \"Index out of bounds\\n\";\r\n        } catch (...) {\r\n            std::cout << \"Something else happened\";\r\n        }\r\n        std::cout << \"Enter an index: \";\r\n    }\r\n}","path":"code/6771/24T2/5.1/exception2.cpp","fileext":"cpp"},"multiple.cpp":{"name":"multiple.cpp","content":"#include <iostream>\r\n#include <vector>\r\n\r\nauto main() -> int\r\n{\r\n    auto items = std::vector<int> {};\r\n    try {\r\n        items.resize(items.max_size() + 1);\r\n    } catch (std::bad_alloc& e) {\r\n        std::cout << \"Out of bounds.\\n\";\r\n    } catch (std::exception&) {\r\n        std::cout << \"General exception.\\n\";\r\n    }\r\n}","path":"code/6771/24T2/5.1/multiple.cpp","fileext":"cpp"}}},"__N_SSG":true}