Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

RESUME

Keyword Abbreviation Token (hex) Version(s) Classification
RESUME RES{Shift+U} D6 3.5, 7.0 Statement
DLOAD D{Shift+L}   D6  4.x  Command and Statement* 
RESUME RES{Shift+U} E3 4.x Statement
GSHAPE G{Shift+S}  E3  3.5, 7.0  Command and Statement 

 
Syntax  
RESUME [ { lineNumber | NEXT } ]
 
Parameters Type Legal Value(s) Default Value Note(s)
lineNumber Unsigned Integer 0 ~ 63999 If used, the program line must exist and it must be a literal number.
 
 
 
Purpose  
Program error control; exit an error trap routine and re-enable error traps in a program.

 
 
Remarks  
RESUME allows three ways to exit an error trap routine (see TRAP).  Without any parameter, BASIC will exit to the same statement that caused the error.  Unless the error trap routine changed a variable used by that statment, that statement will very likely cause the error trap routine to be immediately called again (i.e., an infinite loop).  With the NEXT keyword as the parameter, BASIC will exit to the statement following the one that caused the error.  This is often used.  The final option is to give a specific lineNumber where the program should continue executing.
 
If RESUME is used in direct mode, an ILLEGAL DIRECT ERROR is generated.  If RESUME is used in a program without an error having occurred (i.e., not in a trap routine) then CAN'T RESUME ERROR (or UNABLE TO RESUME ERROR) is generated.
 
Now lets assume an error has occured and called the error trap routine.  Once RESUME is used, error-trapping is re-enabled (it is temporarily disabled when the trap routine is called) unless the trap routine issued TRAP without any lineNumber (which disables error-trapping).
 
If you are having trouble with RESUME (no argument) and RESUME NEXT, then one thing you can try is to use HELP in your trap routine.  This will not only list the line that caused the error (which you should know from variable EL), but also highlights the statement which cause the error.  This is the statement that will be re-executed when RESUME (no argument) is used.  The statement following the highlighted the colon (:) or, if that does not exist the first statement of the next line, is the one that will be executed with RESUME NEXT.
 
Assuming lineNumber is given, it must be a literal line number, like GOTO/GOSUB (but unlike TRAP), or SYNTAX ERROR is generated.  If the lineNumber is not a legal value (see above), an ILLEGAL QUANTITY ERROR is generated.  Any of these errors (like any other error that occurs in the trap routine) will cause BASIC to switch to direct mode (abort the program) and print an error message.  Otherwise, the lineNumber must exist or an UNDEF'D STATMENT ERROR is generated, but unlike any of the other errors, BASIC will not exit to immediate mode and print an error, but instead the TRAP routine will immediately be called again, which usually results in an infinite loop.  This occurs because BASIC re-enables error traps after it evaluates the lineNumber but before it tries to GOTO the lineNumber... sounds like a bug to me!
 
If a lineNumber is given, it should usually be very close to where the error occured, to avoid corruption of the BASIC stack which occurs from skipping LOOP, NEXT, and RETURN statements.  BASIC 4.x (only) has the DISPOSE keyword which can be used to remove entries from the stack.
 
The RESUME statement, no matter what parameter is used (if any) removes the "GOSUB" entry that was put on the stack when the error trap was called.  This makes it almost the same as RETURN, except of course you can specify a lineNumber with RESUME (which makes it into some kind of hybrid RETURN+GOTO statement).
 
Example:
NEW

READY.
10 TRAP 100
20 INPUT "RECTANGULAR X,Y"; X,Y
30 PRINT "POLAR M,A";
40 PRINT SQR(X*X + Y*Y) ",";
50 A = 180/p * ATN(Y/X)
60 PRINT A : PRINT
70 END
100 IF EL <> 50 THEN PRINT "UNEXPECTED" : STOP
110 A = 90*SGN(Y)
120 RESUME NEXT : REM RESUME on line 60
RUN
RECTANGULAR X,Y? 0,4 (user input)
POLAR M,A 4, 90                  note BASIC called the trap routine (not obvious)

READY.
120 PRINT : RESUME 20 : REM Start over
RUN
RECTANGULAR X,Y? 0,4 (user input)
POLAR M,A 4,                     note BASIC called the trap routine...
RECTANGULAR X,Y?                 ...and started over

 
 
 
Compare With  
 
 
Contrast With  
 
See Also  
EL, ER, ERR$, HELPNEXTTRAP
© H2Obsession, 2014
Comments