#include <stdio.h>

class A {
    int *buf;
    A(const A &);               /* no copies */
    void operator=(const A &);
public:
    A() : buf(new int[100]) { printf("  A: buffer allocated\n"); }
    ~A() { delete[] buf; printf("  ~A: buffer freed\n"); }
};

void g(bool fail)
{
    printf("  g: working\n");
    if (fail)
        throw "g failed";
}

void f(bool fail)
{
    A a;
    printf("  f: before g\n");
    g(fail);
    printf("  f: after g\n");
}

int main()
{
    printf("g returns normally:\n");
    f(false);
    printf("g throws:\n");
    try {
        f(true);
    }
    catch (const char *s) {
        printf("  main: caught \"%s\"\n", s);
    }
    return 0;
}
