Changes in tests/exceptions/defaults.cfa [ecfd758:fd54fef]
- File:
-
- 1 edited
-
tests/exceptions/defaults.cfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/exceptions/defaults.cfa
recfd758 rfd54fef 4 4 #include <exception.hfa> 5 5 6 EHM_EXCEPTION(log_message)(6 DATA_EXCEPTION(log_message)( 7 7 char * msg; 8 8 ); 9 9 10 _EHM_DEFINE_COPY(log_message, ) 11 const char * msg(log_message * this) { 10 void ?{}(log_message & this, char * msg) { 11 VTABLE_INIT(this, log_message); 12 this.msg = msg; 13 } 14 15 const char * get_log_message(log_message * this) { 12 16 return this->msg; 13 17 } 14 _EHM_VIRTUAL_TABLE(log_message, , log_vt); 18 19 VTABLE_INSTANCE(log_message)(get_log_message); 15 20 16 21 // Logging messages don't have to be handled. … … 23 28 // We can catch log: 24 29 try { 25 throwResume (log_message){ &log_vt,"Should be printed.\n"};30 throwResume (log_message){"Should be printed.\n"}; 26 31 } catchResume (log_message * this) { 27 32 printf("%s", this->virtual_table->msg(this)); 28 33 } 29 34 // But we don't have to: 30 throwResume (log_message){ &log_vt,"Should not be printed.\n"};35 throwResume (log_message){"Should not be printed.\n"}; 31 36 } 32 37 33 38 // I don't have a good use case for doing the same with termination. 34 EHM_EXCEPTION(jump)();39 TRIVIAL_EXCEPTION(jump); 35 40 void defaultTerminationHandler(jump &) { 36 41 printf("jump default handler.\n"); 37 42 } 38 43 39 EHM_VIRTUAL_TABLE(jump, jump_vt);40 41 44 void jump_test(void) { 42 45 try { 43 throw (jump){ &jump_vt};46 throw (jump){}; 44 47 } catch (jump * this) { 45 48 printf("jump catch handler.\n"); 46 49 } 47 throw (jump){ &jump_vt};50 throw (jump){}; 48 51 } 49 52 50 EHM_EXCEPTION(first)(); 51 EHM_VIRTUAL_TABLE(first, first_vt); 52 53 EHM_EXCEPTION(unhandled_exception)(); 54 EHM_VIRTUAL_TABLE(unhandled_exception, unhandled_vt); 53 TRIVIAL_EXCEPTION(first); 54 TRIVIAL_EXCEPTION(unhandled_exception); 55 55 56 56 void unhandled_test(void) { 57 57 forall(T &, V & | is_exception(T, V)) 58 58 void defaultTerminationHandler(T &) { 59 throw (unhandled_exception){ &unhandled_vt};59 throw (unhandled_exception){}; 60 60 } 61 61 void defaultTerminationHandler(unhandled_exception &) { … … 63 63 } 64 64 try { 65 throw (first){ &first_vt};65 throw (first){}; 66 66 } catch (unhandled_exception * t) { 67 67 printf("Catch unhandled_exception.\n"); … … 69 69 } 70 70 71 EHM_EXCEPTION(second)(); 72 EHM_VIRTUAL_TABLE(second, second_vt); 71 TRIVIAL_EXCEPTION(second); 73 72 74 73 void cross_test(void) { 75 74 void defaultTerminationHandler(first &) { 76 75 printf("cross terminate default\n"); 77 throw (second){ &second_vt};76 throw (second){}; 78 77 } 79 78 void defaultResumptionHandler(first &) { 80 79 printf("cross resume default\n"); 81 throwResume (second){ &second_vt};80 throwResume (second){}; 82 81 } 83 82 try { 84 83 printf("cross terminate throw\n"); 85 throw (first){ &first_vt};84 throw (first){}; 86 85 } catch (second *) { 87 86 printf("cross terminate catch\n"); … … 89 88 try { 90 89 printf("cross resume throw\n"); 91 throwResume (first){ &first_vt};90 throwResume (first){}; 92 91 } catchResume (second *) { 93 92 printf("cross resume catch\n");
Note:
See TracChangeset
for help on using the changeset viewer.