views:

455

answers:

8

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?

A: 

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...

DigitalRoss
I've heard that PL/1 was big and complex for its day, it probably had exceptions, meaning they could be quite old, mid 1960's. COBOL appears to have them now, but I wonder when they were added..
DigitalRoss
Oh, I thought of one more. Quite possibly one of the 999 versions of Lisp was first with an exception-like mechanism.
DigitalRoss
I wrote PL/1 on the VAX in 1986, and it had exception handling built in to the language.
Paul McGuire
I was really referring to the type of exception handling that can be caught, which I don't believe is really the case with `on error goto`. I'm sure you could emulate that using global variables, but AFAIK you can't pass out different exception "types." And it's the same with `setjmp`/`longjmp`. Those are really just `goto` commands, not "exception handling" as we think of it today.
SoaperGEM
I'm not sure I agree wrt setjmp and longjmp, as they exchange a value, which can be a cookie for an arbitrarily elaborate exception typing system. I think you might be more right about basic. Both are clearly exceptions, though, and not sentinel value returns...
DigitalRoss
+4  A: 

C++ had exceptions before Java did.

duffymo
+9  A: 

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).

Crashworks
+6  A: 

CLU had exception handling in the early 1970s.

Barry Brown
+2  A: 

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.

Stephen C
The ability to resume an exception actually exists in Windows exceptions, though it's not a well known/used thing...
Matthew Scharley
@Matthew. So perhaps this is where Windows copied it from :-)
Stephen C
See Stroustrup's discussion of 'terminate vs resume' semantics in "Design and Evolution of C++". The Cedar system which was built using Mesa and initially had a number of 'resume' exceptions, but over time they were all eliminated in favour of 'terminate' semantics. Eventually, Cedar had just one exception left that used 'resume' semantics, and on further review, that was removed too.
Jonathan Leffler
That sounds like (what Common Lisp calls) conditions, which are more generic than exceptions. But upon further inspection, it looks like PL/I offers the same feature. Which raises the question: what language was the first to implement Java/C++/C#/Python/Ruby-style exceptions (and not Mesa/Lisp/PL/I-style restartable conditions)?
Ken
Answer to my own question: possibly CLU (from Liskov's paper, linked above): "We considered and rejected the resumption model present in both PL/I and Mesa because it was complex and also because we believed that most of the time, termination was what was wanted. Furthermore, if resumption were wanted, it could be simulated by passing a procedure as an argument (although closures would be useful here)."
Ken
@Ken - IIRC, Mesa allowed either termination or resumption model, at the discretion of the exception handler. CLU might have been the first language to support ONLY the termination model, but it was not the first to support the termination model.
Stephen C
+1  A: 

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:

  1. AB49.1983-May : "A Proposal for Exception Handling in ALGOL 68", by C. H. Lindsey - Pages: 10 - 15

  2. 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.

NevilleDNZ
+13  A: 

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).

mipadi
+1 for the reference
rick schott
A: 

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.

Bruce Hobbs