// Resumption Exception Tests #include #include "except-io.hfa" TRIVIAL_EXCEPTION(yin); TRIVIAL_EXCEPTION(yang); TRIVIAL_EXCEPTION(zen); TRIVIAL_EXCEPTION(moment_of, zen); void in_void(void); int main(int argc, char * argv[]) { // The simple throw catchResume test. try { loud_exit a = "simple try clause"; printf("simple throw\n"); throwResume (zen){}; printf("end of try clause\n"); } catchResume (zen * error) { loud_exit a = "simple catch clause"; printf("simple catch\n"); } printf("\n"); // Throw catch-all test. try { throwResume (zen){}; } catchResume (exception_t * error) { printf("catch-all\n"); } printf("\n"); // Catch a parent of the given exception. try { printf("throwing child exception\n"); throwResume (moment_of){}; } catchResume (zen *) { printf("inner parent match\n"); } catchResume (moment_of *) { printf("outer exact match\n"); } printf("\n"); // Don't catch if handler does not match exception. try { try { throwResume (yin){}; } catchResume (zen *) { printf("caught yin as zen\n"); } } catchResume (yang *) { printf("caught yin as yang\n"); } catchResume (yin *) { printf("caught yin as yin\n"); } printf("\n"); // Test rethrowing an exception. try { try { loud_exit a = "rethrow inner try"; printf("rethrow inner try\n"); throwResume (zen){}; } catchResume (zen *) { loud_exit a = "rethrowing catch clause"; printf("caught throw, will rethrow\n"); throwResume; } } catchResume (zen *) { loud_exit a = "rethrow catch clause"; printf("caught rethrow\n"); } printf("\n"); // Throw a different exception in a catch. try { try { throwResume (yin){}; } catchResume (yin *) { printf("caught yin, will throw yang\n"); throwResume (yang){}; } catchResume (yang *) { printf("caught exception from same try\n"); } } catchResume (yang *) { printf("caught yang\n"); } printf("\n"); // Another throw in the catch does not interfere. try { try { printf("throwing first exception\n"); throwResume (yin){}; } catchResume (yin *) { printf("caught first exception\n"); try { printf("throwing second exception\n"); throwResume (yang){}; } catchResume (yang *) { printf("caught second exception\n"); } throwResume; } } catchResume (yin *) { printf("recaught first exception\n"); } catchResume (yang *) { printf("caught second exception (bad location)\n"); } printf("\n"); // Check successive operations. try { try { throwResume (zen){}; throwResume (zen){}; } catchResume (zen *) { printf("inner catch\n"); } throwResume (zen){}; } catchResume (zen *) { printf("outer catch\n"); } printf("\n"); in_void(); } // Do a throw and rethrow in a void function. void in_void(void) { try { try { printf("throw\n"); throwResume (zen){}; } catchResume (zen *) { printf("rethrow\n"); throwResume; } } catchResume (zen *) { printf("handle\n"); } }