// Testing polymophic exception types. #include FORALL_TRIVIAL_EXCEPTION(proxy, (otype T), (T)); FORALL_TRIVIAL_INSTANCE(proxy, (otype U), (U)) const char * msg(proxy(int) * this) { return "proxy(int)"; } const char * msg(proxy(char) * this) { return "proxy(char)"; } POLY_VTABLE_INSTANCE(proxy, int)(msg); POLY_VTABLE_INSTANCE(proxy, char)(msg); void proxy_test(void) { try { throw (proxy(int)){}; } catch (proxy(int) *) { printf("terminate catch\n"); } try { throwResume (proxy(char)){}; } catchResume (proxy(char) *) { printf("resume catch\n"); } try { throw (proxy(char)){}; } catch (proxy(int) *) { printf("caught proxy(int)\n"); } catch (proxy(char) *) { printf("caught proxy(char)\n"); } } FORALL_DATA_EXCEPTION(cell, (otype T), (T))( T data; ); FORALL_DATA_INSTANCE(cell, (otype T), (T)) const char * msg(cell(int) * this) { return "cell(int)"; } const char * msg(cell(char) * this) { return "cell(char)"; } const char * msg(cell(bool) * this) { return "cell(bool)"; } POLY_VTABLE_INSTANCE(cell, int)(msg); POLY_VTABLE_INSTANCE(cell, char)(msg); POLY_VTABLE_INSTANCE(cell, bool)(msg); void cell_test(void) { try { cell(int) except; except.data = -7; throw except; } catch (cell(int) * error) { printf("%d\n", error->data); } try { cell(bool) ball; ball.data = false; throwResume ball; printf("%i\n", ball.data); } catchResume (cell(bool) * error) { printf("%i\n", error->data); error->data = true; } } int main(int argc, char * argv[]) { proxy_test(); printf("\n"); cell_test(); }