#include #include "throw.h" class foo { int i; public: foo(int i) : i(i) { fprintf(stderr, "foo::constructor 1\n"); } foo() throw(int) : i(1) { fprintf(stderr, "foo::constructor 2\n"); throw(1); } int get() const { return i; } }; static foo o2(2); int main() { int rc = 0; /* static foo - inline implementation */ if (o2.get() == 2) fprintf(stderr, "o2 ok\n"); else { rc++; fprintf(stderr, "o2 failed\n"); } /* foo - inline implementation */ try { fprintf(stderr, "foo creating\n"); foo o; fprintf(stderr, "foo no throw!\n"); printf("error: foo::foo() didn't throw!\n"); rc += o.get(); } catch (int e) { fprintf(stderr, "foo caught e=%d (ok)\n", e); } /* bar - external implementation */ try { fprintf(stderr, "bar creating\n"); bar o; fprintf(stderr, "bar no throw!\n"); printf("error: bar::bar() didn't throw!\n"); rc += o.get(); } catch (int e) { fprintf(stderr, "bar caught e=%d (ok)\n", e); } return rc; }