This question is not a technical but a historical one. I was just thinking today that I\'ve also thought of Java as the \"first\" language to use exception handling, until I
The errorset
function in Lisp 1.5, described in a 1962 reference manual, is an early form of exception handling. In The Evolution of Lisp, Gabriel and Steele make these remarks, evidently getting the name of the operator slightly wrong and simplifying its syntax (P. 9-10):
In Lisp 1.5, certain built-in functions might signal errors, when given incorrect arguments, for example. Signaling an error normally resulted in program termination or invocation of a debugger. Lisp 1.5 also had the function ERRSET , which was useful for controlled execution of code that might cause an error. The special form
(errset form)
evaluates form in a context in which errors do not terminate the program or enter the debugger. If form does not cause an error, ERRSET returns a singleton list of the value. If execution of form does cause an error, the ERRSET form quietly returns NIL .
MacLisp added the function ERR , which signals an error. If ERR is invoked within the dynamic context of an ERRSET form, then the argument to ERR is returned as the value of the ERRSET form.
Programmers soon began to use ERRSET and ERR not to trap and signal errors but for more general control purposes (dynamic non-local exits). Unfortunately, this use of ERRSET also quietly trapped unexpected errors, making programs harder to debug. A new pair of primitives, CATCH and THROW , was introduced into MacLisp in June 1972 so that ERRSET could be reserved for its intended use of error trapping.
The manual has, of course, the details, on Page 34, section "6.4 The Cons Counter and Errorset".
It looks like errorset
interacts with the "cons counter", a memory allocation watchdog. The user of errorset
must specify an integer value n
, which specifies how many cons cells can be allocated in the protected computation before a trap will occur.
The description ends with these words:
If an error occurs inside of an errorset, then the value of errorset is NIL. If vari- ables bound outside of the errorset have not been altered by using cset or set, and if no damage has been done by pseudo-functions, it may be possible to continue computation in a different direction when one path results in an error.
This clearly shows that the construct is suitable for locally trapping an error, and then recovering (continuing computation "in a different direction when one path results in an error").
ANSI Common Lisp "conditions" show a lot of inspiration from the PL/I "conditions" system. However, PL/I was first available in 1966, a few years after Lisp 1.5's errset
. The first PL/I reference manual, dated 1965, does already describe ON-units and conditions.
Programming Languages: Principles and Practice, 2nd edition, by Kenneth C. Louden (a notable textbook on programming languages) notes that "Exception handling was pioneered by the language PL/I in the 1960s and significantly advanced in CLU in the 1970s. However, it was only in the 1980s and early 1990s that design questions were largely resolved" (283).
Algol 68's "transput" had "event" handling, but it wasn't streamline enough for the programmer to extent it.
The ALGOL 68 standard uses event routines extensively in the "standard transput" (stdio) to manage the various events that arise when data is read (or written) to a file or external device. The built in "on event" routines are:
In 1983 Proposals were being accepted to allowing a programmer defined their own exceptions. AFAIK none of these proposals were accepted by the United Nation's IFIP.
However the Russians standards body "GOST" did standardize exception handling near the end of Glasnost/Гласност in the standard "GOST 27975-88 Programming language ALGOL 68 extended - Язык программирования АЛГОЛ 68 расширенный"
GOST 27975-88 used the additional keywords: MODULE, PUB, POSTLUDE, NEST, EGG, ON, EXCEPTION and RAISE.
Here are the original UK proposals:
AB49.1983-May : "A Proposal for Exception Handling in ALGOL 68", by C. H. Lindsey - Pages: 10 - 15
AB49.1983-May : "An Exception-Handling Mechanism for ALGOL 68", by Martyn Thomas - Pages: 16 - 17
They appear similar to what is now implemented in python.
Lindsey's Example:
EXCEPTION singular = new exception ; # EXCEPTION la a new mode #
PROC gauss = ( REF [ , ] REAL a. REF [ ] REAL rhs ) VOID :
COMMENT a procedure to solve a set of simultaneous
equations COMMENT
BEGIN C the usual algorithm for gaussian elimination which, at some
point, may discover that a is singular C ;
IF C it makes this discovery C
THEN RAISE singular
FI;
C rest of algorithm CO
END;
Exceptions bulitin were: time exhausted, space exhausted, arithmetic error, bounds error, scope error, transput impossible, file end, char error, value error and format error
Martyn Thomas's Example:
BEGIN
on ( overflow , overflow handler ) ;
on ( bound check, boundcheckhandler ) ;
C body of the closed - clause C
EXIT
overflow handler:
C handle overflow exceptions C
EXIT
bound check handler:
C handle bound check C
END
BTW: The Soviet's Space Shuttle Buran/Буран completed one unmanned spaceflight in 1988, the automatic landing system was written in Algol. The Amercian's still deploy numerous bits of military/space apparatus in Jovial (Algol 58), and this may contain exception handling from the 1950s. Anyone got any ideas on this?...
Wikipedia: Buran_(spacecraft): The shuttle orbited the Earth twice in 206 minutes of flight. It performed an automated landing on the shuttle runway at Baikonur Cosmodrome where, despite a lateral wind speed of 61.2 kilometres (38.0 mi) /hour, it landed only 3 metres (9.8 ft) laterally and 10 metres (33 ft) longitudinally from the target.
CLU had exception handling in the early 1970s.
We should not forget C which had setjmp(3)
and longjmp(3)
in the 1970's.
And before that, Basic, with on error goto...
I never saw an algol68 implementation, but I heard it had the kitchen sink...
Regarding COBOL's support for exception handling: Classic (I/O and arithmetic) exception handling has been around since at least the 1968 COBOL standard. OO exception handling was added to COBOL in the 2002 standard.