Exception handling of PRINT USING statements

On a PRINT USING statement, if a format overflow occurrs, default exception handling is applied, and it fills the output field with asterisks, reports the unformatted representation of value on the next line, and continues printing on the following line in a position identical that would have resulted if no exception occurred.
For example,

10 LET a=5000
20 PRINT USING "#### ####":2*a, a
30 END

results

****
 10000 
     5000


When you want to continue without outputting extra lines, use USING$ functions in place of PRINT USING.
For example, changing the 20th line in the above program into

20 PRINT USING$("####", 2*a);" ";USING$("####", a)

results

**** 5000



USING$ functions deal with only numeric values, but you can define a function which formats string values.
For example, the function that makes a string n characters by the way truncating it if the length of it is longer than n, appending apace characters if the length is shorter than n can be defined as follows.

DEF format$(s$,n) = s$(1:n) & REPEAT$(" ",MAX(0,n-LEN(s$)))



When a PRINT USING statement is enclosed within a WHEN EXCEPTION ~ USE block, an exception of EXTYPE 8203 or 8204 is raised if a format overflow occurs. If you are not satisfied by the method above, you can write an original recovery method.
Example.

WHEN EXCEPTION IN
   PRINT USING "#### ####":2*a, a
USE
   SELECT CASE EXTYPE
   CASE 8203,8204
   ! Write the recovery method here.
   CASE ELSE
      EXIT HANDLER
   END SELECT 
END WHEN

Back