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 realized that my reason for thinking this way is probably because Java was the first language I encountered that used it, but I had no historical data to back up that conclusion. Nowadays exception handling is commonplace in all modern languages, so I'm just wondering: does anyone know when it first started being widely used? And what language was the first to start using it?
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...
Exception handling really goes back to even before programming languages; at first, it was a hardware mechanism for trapping error conditions (those that caused an execution halt) and optionally branching to a subroutine.
For example, the VAX CPU could detect when a virtual address that had no physical mapping was accessed, and call into a subroutine that either loaded the appropriate page from swap, or halted the program. The mechanism is essentially the same in modern processors (look up "translation lookaside buffer"). So in a sense the first language to have exceptions was assembly.
The earliest structured languages to have exceptions appear to be PL/I and CLU (see Mipadi above).
I can remember using exception handlers in Xerox's Mesa language in ... um ... 1984. The language existed well before then. Mesa had an interesting exception model. In addition to propagating and handling an exception in the normal way, a handler could "resume" an exception, causing execution to return from the "throw" statement.
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:
- on char error, on format error, on line end, on logical file end, on page end, on physical file end & on value error
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.
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).
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.