On a first run there’s no highscore file, no settings file, no cache. The program tries to read it, MMBasic bails out, done. For a while I guarded these with MM.INFO(EXISTS file$) up front, which works, but means three lines of ceremony around every file open. ON ERROR SKIP makes it much tighter.

The idea

ON ERROR SKIP tells MMBasic to skip past the next error instead of aborting. MM.ERRNO then holds the error code (0 means no error). Together they let you simply try to open a file and read off MM.ERRNO whether it actually worked.

SUB LoadHighscores()
  LOCAL INTEGER i, score, lv
  LOCAL STRING name$

  ON ERROR SKIP
  OPEN "highscores.dat" FOR INPUT AS #1

  IF MM.ERRNO = 0 THEN
    FOR i = 0 TO 9
      INPUT #1, name$, score, lv
      hs_names$(i) = name$
      hs_scores(i) = score
      hs_levels(i) = lv
    NEXT i
    CLOSE #1
  ELSE
    SaveHighscores()  ' write defaults so the file exists next run
  END IF

  ON ERROR ABORT
END SUB

If the file exists and is readable, it’s read. If not, the program doesn’t fall over, it just writes the defaults out. Next start the file is there and the happy path takes over.

Reset with ON ERROR ABORT

ON ERROR SKIP doesn’t only cover the next line, it stays active until you turn it off. Forget that and you swallow every later error silently, then spend ages wondering why something doesn’t work. My habit: reset with ON ERROR ABORT at the end of the sub so normal abort behaviour comes back.

Guarding a single line

ON ERROR SKIP only covers the next statement. So when you only want to protect a single line, drop it right above and skip the ABORT afterwards:

ON ERROR SKIP
KILL "tempfile.tmp"
' KILL won't crash if the file isn't there
' Normal abort behaviour resumes automatically

That’s the compact form for cleanup work where it doesn’t matter whether the file was already gone.

Both shapes saved me from MM.INFO(EXISTS …) checks in most situations. The code reads closer to what it means: “try to read, fail soft if you must”. Which is the whole point of error handling when the language does it right.