Changeset 26be854 for tests/exceptions
- Timestamp:
- Oct 1, 2023, 12:25:55 PM (15 months ago)
- Branches:
- master
- Children:
- 7a925a41
- Parents:
- fd775ae
- Location:
- tests/exceptions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/exceptions/hotpotato.cfa
rfd775ae r26be854 35 35 ExceptionDecl( Explode ); 36 36 ExceptionDecl( Terminate, Player * victim; ); 37 ExceptionDecl( Election , Player * player;);37 ExceptionDecl( Election ); 38 38 ExceptionDecl( cmd_error ); // convert(...) throws out_of_range or invalid_argument 39 39 … … 47 47 void countdown( Potato & potato ) with(potato) { 48 48 timer += 1; 49 if ( timer == deadline ) throw ExceptionInst( Explode );49 if ( timer == deadline ) throwResume ExceptionInst( Explode ); 50 50 } // countdown 51 51 … … 86 86 void main( Player & player ) with(player) { 87 87 suspend; // return immediately after establishing starter 88 89 88 try { 90 89 for ( ;; ) { … … 93 92 if ( partner[LEFT] == &player ) { // stop when only one player 94 93 sout | id | " wins the Match!"; 95 break;94 return; 96 95 } // exit 97 96 … … 112 111 sout | "election"; 113 112 sout | " -> " | id | nonl; 114 if ( id > getId( *election->player ) ) election->player= &player; // set umpire to highest id so far113 if ( id > getId( umpire ) ) &umpire = &player; // set umpire to highest id so far 115 114 vote( *partner[RIGHT], *election ); 116 } catch ( Explode * ) {115 } catchResume ( Explode * ) { 117 116 sout | id | " is eliminated"; 118 117 if ( &player == &umpire ) { 119 118 id = -1; // remove from election 120 vote( *partner[RIGHT], ExceptionInst( Election, &player ) ); // start election 121 try { 122 poll(); 123 } catchResume( Election * election ) { 124 &umpire = election->player; 125 sout | " : umpire " | getId( *election->player ); 126 } 119 vote( *partner[RIGHT], ExceptionInst( Election ) ); // start election 120 try { poll(); } catchResume( Election * election ) {} // handle end of election 121 sout | " : umpire " | getId( umpire ); 127 122 } // if 128 123 resumeAt( umpire, ExceptionInst( Terminate, &player ) ); -
tests/exceptions/hotpotato_checked.cfa
rfd775ae r26be854 35 35 ExceptionDecl( Explode ); 36 36 ExceptionDecl( Terminate, Player * victim; ); 37 ExceptionDecl( Election , Player * player;);37 ExceptionDecl( Election ); 38 38 ExceptionDecl( cmd_error ); // convert(...) throws out_of_range or invalid_argument 39 39 … … 47 47 void countdown( Potato & potato ) with(potato) { 48 48 timer += 1; 49 if ( timer == deadline ) throw ExceptionInst( Explode );49 if ( timer == deadline ) throwResume ExceptionInst( Explode ); 50 50 } // countdown 51 51 … … 96 96 if ( partner[LEFT] == &player ) { // stop when only one player 97 97 sout | id | " wins the Match!"; 98 break;98 return; 99 99 } // exit 100 100 … … 116 116 sout | "election"; 117 117 sout | " -> " | id | nonl; 118 if ( id > getId( *election->player ) ) election->player= &player; // set umpire to highest id so far118 if ( id > getId( umpire ) ) &umpire = &player; // set umpire to highest id so far 119 119 resumeAt( *partner[RIGHT], *election ); 120 120 disable_ehm(); // disable ehm since we can't handle execption thrown in vote here and want to poll later 121 121 vote( *partner[RIGHT] ); 122 122 enable_ehm(); // enable after vote 123 } catch 123 } catchResume( Explode * ) { 124 124 sout | id | " is eliminated"; 125 125 if ( &player == &umpire ) { 126 126 try { 127 127 id = -1; // remove from election 128 resumeAt( *partner[RIGHT], ExceptionInst( Election , &player) );128 resumeAt( *partner[RIGHT], ExceptionInst( Election ) ); 129 129 vote( *partner[RIGHT] ); // start election 130 130 checked_poll(); 131 131 } catchResume( Election * election ) { 132 &umpire = election->player; 133 sout | " : umpire " | getId( *election->player ); 132 sout | " : umpire " | getId( umpire ); 134 133 } // try 135 134 } // if
Note: See TracChangeset
for help on using the changeset viewer.