Changeset ecfd758 for tests/exceptions/defaults.cfa
- Timestamp:
- Apr 9, 2021, 2:11:43 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b91bfde
- Parents:
- e07b589
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/exceptions/defaults.cfa
re07b589 recfd758 4 4 #include <exception.hfa> 5 5 6 DATA_EXCEPTION(log_message)(6 EHM_EXCEPTION(log_message)( 7 7 char * msg; 8 8 ); 9 9 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) { 10 _EHM_DEFINE_COPY(log_message, ) 11 const char * msg(log_message * this) { 16 12 return this->msg; 17 13 } 18 19 VTABLE_INSTANCE(log_message)(get_log_message); 14 _EHM_VIRTUAL_TABLE(log_message, , log_vt); 20 15 21 16 // Logging messages don't have to be handled. … … 28 23 // We can catch log: 29 24 try { 30 throwResume (log_message){ "Should be printed.\n"};25 throwResume (log_message){&log_vt, "Should be printed.\n"}; 31 26 } catchResume (log_message * this) { 32 27 printf("%s", this->virtual_table->msg(this)); 33 28 } 34 29 // But we don't have to: 35 throwResume (log_message){ "Should not be printed.\n"};30 throwResume (log_message){&log_vt, "Should not be printed.\n"}; 36 31 } 37 32 38 33 // I don't have a good use case for doing the same with termination. 39 TRIVIAL_EXCEPTION(jump);34 EHM_EXCEPTION(jump)(); 40 35 void defaultTerminationHandler(jump &) { 41 36 printf("jump default handler.\n"); 42 37 } 43 38 39 EHM_VIRTUAL_TABLE(jump, jump_vt); 40 44 41 void jump_test(void) { 45 42 try { 46 throw (jump){ };43 throw (jump){&jump_vt}; 47 44 } catch (jump * this) { 48 45 printf("jump catch handler.\n"); 49 46 } 50 throw (jump){ };47 throw (jump){&jump_vt}; 51 48 } 52 49 53 TRIVIAL_EXCEPTION(first); 54 TRIVIAL_EXCEPTION(unhandled_exception); 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); 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){ };59 throw (unhandled_exception){&unhandled_vt}; 60 60 } 61 61 void defaultTerminationHandler(unhandled_exception &) { … … 63 63 } 64 64 try { 65 throw (first){ };65 throw (first){&first_vt}; 66 66 } catch (unhandled_exception * t) { 67 67 printf("Catch unhandled_exception.\n"); … … 69 69 } 70 70 71 TRIVIAL_EXCEPTION(second); 71 EHM_EXCEPTION(second)(); 72 EHM_VIRTUAL_TABLE(second, second_vt); 72 73 73 74 void cross_test(void) { 74 75 void defaultTerminationHandler(first &) { 75 76 printf("cross terminate default\n"); 76 throw (second){ };77 throw (second){&second_vt}; 77 78 } 78 79 void defaultResumptionHandler(first &) { 79 80 printf("cross resume default\n"); 80 throwResume (second){ };81 throwResume (second){&second_vt}; 81 82 } 82 83 try { 83 84 printf("cross terminate throw\n"); 84 throw (first){ };85 throw (first){&first_vt}; 85 86 } catch (second *) { 86 87 printf("cross terminate catch\n"); … … 88 89 try { 89 90 printf("cross resume throw\n"); 90 throwResume (first){ };91 throwResume (first){&first_vt}; 91 92 } catchResume (second *) { 92 93 printf("cross resume catch\n");
Note: See TracChangeset
for help on using the changeset viewer.