/*
CS371p: Quiz #5 (5 pts)
*/

/* -----------------------------------------------------------------------
1. Many languages permit a group of objects working together to be
   combined into a unit. What is that feature called in Java? In C++?
   [Sec. 2.1, Pg. 27]
   (2 pts)

packages, namespaces
*/

/* -----------------------------------------------------------------------
2. What is the output of the following program?
   (2 pts)

h1 g1 f1
g2 f2
*/

#include <iostream>  // cout, endl
#include <stdexcept> // domain_error, range_error

using namespace std;

void h (bool b) {
    try {
        if (b)
            throw domain_error("abc");
        cout << "h1 ";
        }
    catch (range_error e) {
        cout << "h2 ";}}

void g (bool b) {
    try {
        h(b);
        cout << "g1 ";
        }
    catch (domain_error e) {
        cout << "g2 ";
        throw;
        cout << "g3 ";}}

void f (bool b) {
    try {
        g(b);
        cout << "f1 ";
        }
    catch (domain_error e) {
        cout << "f2 ";}}

int main () {
    f(false);
    cout << endl;
    f(true);
    cout << endl;
    return 0;}


syntax highlighted by Code2HTML, v. 0.9.1