Changeset 26be854 for tests/exceptions/hotpotato.cfa
- Timestamp:
- Oct 1, 2023, 12:25:55 PM (9 months ago)
- Branches:
- master
- Children:
- 7a925a41
- Parents:
- fd775ae
- File:
-
- 1 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 ) );
Note: See TracChangeset
for help on using the changeset viewer.