On error goto ... and similar commands, error handling

I remember this or similar commands (resume) on some BASIC dialects (VBA, Simon’s BASIC). Direct mode only?
A beginner would think: Great, no need for thinking and writing good code, the computer is smart enough anyway.
But syntax errors, wrong code logic, hardware failures etc are not covered by this.
On a pdp8 code, I found an instruction ‘Skip on error’ (at least on peripherals, like paper empty or switched off).

Industrial computers including PLCs have different techniques like backup batteries, backup code but also routines after power failures or hardware issues.

Other software/systems have auto saving, monitoring of temperatures, currents, amount of free (RAM or disc) memory etc.
Even today there are crashes on different OSs for unknown reasons. Nowadays, memory dumps are too large and often useless.

On vintage systems, which had similar instructions, and how useful were they and how often used?
And on writing (modern) code, how important is it to have many error handlings and error messages for every possible error, when having a detailed manual. Often, the latter one is missing.

1 Like

The “skip on error” thing on the PDP-8 is just how the PDP-8 handles most conditional jumps. The ISZ instruction - Increment, Skip Zero is a fundamental instruction - when the target is zero the next instruction is skipped, so it lets you insert a jump instruction so it then become jump when not zero… And so on, so that idea carries over to hardware - read a character from a TTY is then:

TTYC,   KSFIOT          / AWAIT INPUT
        JMP     TTYC
        KRBIOT          / GET A CHARACTER

The KSFIOT skips the next instruction when there is a character ready to read.

On error handling - a GPIO library I wrote some time back was designed to fail if the setup code could not access the GPIO hardware. My thoughts were that if you can’t access the hardware then it’s game over. Lights not going to light, robots not going to move, ventilator isn’t going to ventilate.

I got complaints, but my response was mostly along the lines of; Well, you can’t access the hardware and NOTHING your code can do can remedy that now, so just STOP and fix the error.

I got more complaints, so I added a means for it to return a failure code to the caller. Who then never checked it.

So who knows.

Yes, print a nice error message, then stop. Just stop. Did Retry in “Abort, Retry, Fail?” ever work? (and what was the difference between an Abort or a Fail?)

ON ERROR GOTO… Was handy sometimes - Trying to open a file in a “database” program when you had the wrong disk inserted in the drive on an Apple II for example but there’s a line to be drawn between an ever ending loop saying “Please insert the right disc” and halting with “beep Look you dodo, put the right disc in ok?”

-Gordon

The earliest error trap I do know of is from the UNIVAC I, which would use location 0 as a jump vector on “normal” run-time errors, esp. useful for out of bounds divisions and divisions by zero. (The manual instructs you to set this up before any division.)

(“Normal”, as about any circuitry, including the main bus, was duplicated and the machine would monitor and compare signals and results and halt on a hardware error, if there was any discrepancy detected. This also makes for the rather impressive console, since about every control is duplicated.)

I think, most systems had some kind of error trap for divisions. (The absolute value of the divisor must be greater than the absolute value of the dividend for a successful fixed-point division. As this was a common error condition, bound checking was usually part of any software or hardware routine.)

1 Like

Concerning the PDP8 error:
The opcode is 6663 (PSKE).
LE8-0: Skip on Error (on pdp8emu disassembly).
I found details on a 500+ pages DEC PDF, I think about the OMNIBUS.
I was right. It’s the line printer. It sends a signal when it’s on. If not, it’s an error and the code continues.

I later found similar instructions

KK8-E: Skip if interrupts on, and turn interrupts off
DP8-EAEB: Skip of Transmit Word Count Overflow
KP8-E Skip on Low Power

There are almost all instructions (lookup table of 4096) . Some are still empty, some few are on the MAC emu.

I think, at this point, it may be worth diving a bit more into the history of DEC’s skip instructions. Meaning, having a look at the PDP-1 (announcement and first prototype 1959, first production prototype at BBN 1960, commercial introduction 1961).

Generally, the PDP-1 uses skip instructions (as opposed to branching) for any conditions. These skip instructions are all in a microcoded and microprogrammable group (meaning, you may combine any of its members in single instruction by OR-ing their bit-patterns), the “skip group”, which gives you

  • SMA – skip on minus AC (sign bit set)
  • SPA – skip on plus AC (sign bit clear)
  • SZA – skip on (+) zero AC (no bits set)
  • SZFn – skip on programmer flag n (1…6) zero
  • SZSn – skip on sense switch n (1…6) zero
  • SZO – skip on overflow flag zero

However, there’s also another skip instruction, similar to what’s on the PDP-8, providing an essential building block for any loops counting up from a negative number to zero,

  • ISP addr – index (increment) addr and skip next instruction, if it’s zero after the increment

as well as two (non-combinable) skip instructions for comparing the accumulator to the contents of a given address (skip on equal and skip on unequal).

There’s just a single built-in instruction (SZO), which actually examines the error status of the machine, namely the overflow flag, which is set on an overflow of an addition. (On a side-note, I know no MIT code that would make use of this, while a display routine by Ben Gurley, the designer of the PDP-1, makes frequent use of it. – Gurley’s code uses overflow for implicit range checking, while code originating at MIT tends to be more defensive about these things. Also, Gurly’s code isn’t that tight or optimized, giving the impression that the machine is fast and resources are ample, anyways.)

Initially, there are no I/O related error states to be checked. Rather, the PDP-1 makes use of a synchronization pules for it’s IO equipment, which generally operates asynchronously, and there are variations of IO instructions that will halt and await such a “completion pulse” from the peripheral device. (There’s also a rather sophisticated interrupt circuitry, “sequence break” in DEC terms, and DMA, but this is another story.)

Apart from SZO, which is really an outlier (as it also clears the flag on read, as we know it from interrupt states on later hardware), there’s no notion of an error condition. This only comes into play with the BBN routine for division:

/BBN Divide subroutine

      (...)

dv2,  sub idv     / initial subtraction (dividend - divisor)
      sma         / negative? (divisor > dividend)
      jmp dve     / no, abort on overflow
      
      (...)

      idx dv1     / good divide, increment return address
dve,  idx dv1     / increment return address

      (...)

As we may see, if the divisor isn’t greater than the dividend, we abort the routine at label “dve”, where what’s used as the return address is incremented. As we me also see, just before this, taking the normal path, the return address is incremented, as well. Therefore, there are 2 effective exits, one for the error condition and one, immediately after this, for a successful division.

As the BBN routine was soon implemented in hardware as the “automatic multiply and divide, type 10”, this became DEC’s first error trap: if we call a division, the address immediately after this is where we return on an error condition, otherwise, this address is skipped on a successful operation. Notably, this is not your common skip instruction, but comes from a different direction.

On the PDP-8, we see lots of skip instructions related to peripheral hardware states. (As mentioned before, this was mostly handled by a “completion pulse” on the PDP-1). On the PDP-1, we get the first glimpse of this in 1964, with the Automatic Magnetic Tape Control, Type 510:

  • SCF – skip if tape control free

There had been tape controllers before this, namely the Programmed Magnetic Tape Control, Type 51, and its more sophisticated twin, the Automatic Magnetic Tape Control, Type 52, but neither of these gave you an additional skip instruction. It’s only with the Type 510 that we get this on the PDP-1. And this isn’t mentioned in the June 1963 handbook, but it’s in the PDP-1 Handbook from October 1964, and it’s in the price list from June 1964, where it’s all yours for the reasonable price of just USD 21,200 ($ 205,735 in today’s money).

It’s certainly something which the beginner could misunderstand! Although perhaps the main case is errors in external circumstances - failure to access files, timeouts from peripherals, absence of peripherals - it can also be useful to fail cleanly when there’s another kind of problem, whether it be due to a division by zero or a coding logic error. A robot or a computer-controlled mechanism - anything which handles human safety or money - might advantageously be brought to a safe quiescent state, rather than ploughing ahead.

The old trick of using a piezo lighter to gain credit in a vending machine, video game, or slot machine, is a case in point: the code that’s running may go astray because of malicious external interference, and it shouldn’t start paying out or giving credit. (A watchdog timer can help out in this case.)