Origin of try/catch/finally syntax
Asked Answered
F

4

11

Question for the etymology wizards out there: which programming language was the first to use the try/catch/finally syntax found in today's Java/.NET languages?

Footstep answered 23/5, 2011 at 20:26 Comment(1)
Are you querying the very specific try/catch/finally syntax, or the concept behind them? If the former, than C++ does not have finally, and .Net came after Java. If the Latter than Lisp predates them by a long way.Herwick
C
8

I believe it was C++ and I think Java/C# added finally for resource cleanup (finally is not in C++). Unfortunately I have no references... yet.

Neat page of all the exception syntax: http://en.wikipedia.org/wiki/Exception_handling_syntax

I believe it is C++. If its not then Stroustrup needs to give credit. In his paper: http://www.research.att.com/~bs/except.pdf He does not mention any influences and does not reference any other material other than his own.

Callas answered 23/5, 2011 at 20:32 Comment(10)
There's no finally in C++, is there?Cystocele
I think erlang try/catch/after predates any use by C++, but I don't have a good referenceManicurist
@Chris Dodd Its pretty trivial to see that that is unlikely (erlang before c++) Erlang: "The first version was developed by Joe Armstrong in 1986." C++: "It was developed by Bjarne Stroustrup starting in 1979" -From wikipediaCallas
The paper you cite is about a particular implementation technique. Exceptions in C++ are older than that (see the history cited by Nemanja). Exceptions are in turn more than a decade older than C++, but I don't know who introduced the precise syntax.Pelargonium
@Gilles the paper sited by @Nemanja was not claimed to be an Academic Paper where the paper I sited was (thus I would expect references of credit). I'm sure the idea of exception handling is older but the question is about the syntax. @Gilles kind of unfair to nitpick and make claims when you have no references.Callas
BTW last comment was not put @Nemanja's find down. The paper he found is superior in corresponding content.Callas
@Adam: An academic paper on implementation techniques would not need to credit syntax, which the question was about. In fact academic papers rarely give citations for concrete syntax at all.Pelargonium
@Gilles That is probably true but the few I have seen do (Python, F#, Objective C, and Squeak). Still the question is on syntax.Callas
Good discussion, thanks folks. This question came up because Try::Tiny, a Perl module that is one of the de facto standards for exception handling in that realm, makes use of the try-catch-finally syntax but gives it completely different semantics. I wanted to make sure I had my history straight before I dissed it.Footstep
The research.att link is broken :-(Aliquot
G
5

Posted on Twitter by Mike Fikes, shared with me by Paweł Kapała:

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 [emphasis mine] so that ERRSET could be reserved for its intended use of error trapping.

The lesson of ERRSET and CATCH is important. The designers of ERRSET and later ERR had in mind a particular situation and defined a pair of primitives to address that situation. But because these facilities provided a combination of useful and powerful capabilities (error trapping plus dynamic non-local exits), programmers began to use these facilities in unintended ways. Then the designers had to go back and split the desired into pieces with alternative interfaces. This pattern of careful design, unintended use, and later redesign is common in the evolution of Lisp.

— from “The Evolution of Lisp,” by Guy Steele and Richard Gabriel

image of this text from the twit below Source: https://twitter.com/mfikes/status/881943130588753920

<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">“The Evolution of Lisp,” by Guy Steele and Richard Gabriel</p>&mdash; Mike Fikes (@mfikes) <a href="https://twitter.com/mfikes/status/881950560508940288">July 3, 2017</a></blockquote>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
Grandpapa answered 7/7, 2017 at 18:2 Comment(1)
Oh, it already appeared on Wikipedia on April 13th, 2014: en.wikipedia.org/wiki/Exception_handling#History (diff: en.wikipedia.org/w/… )Grandpapa
F
2

C++ was the first major programming language to introduce exceptions (finally is not needed in C++ because destructors are deterministic). From Stroustrup's paper: http://www2.research.att.com/~bs/hopl2.pdf

the greatest influence on the C++ exception handling design was the work on fault−t olerant systems started at the University of Newcastle in England by Brian Randell and his colleagues and continued in many places since

Fief answered 23/5, 2011 at 20:57 Comment(5)
Define “major”. Lisp had exception handling through unwind-protect, of course with a very different syntax. There were more recognizable exceptions in Algol 68 and CLU, but with different keywords (not try and catch).Pelargonium
@Giles: The question was very specific: exceptions with try-catch-finally syntax.Fief
I just got @Gillesd also. He clearly did not read the question.Callas
Yes, I was just objecting to your first sentence, which is tangential to the question, but wrong.Pelargonium
@Gilles If you interpret the question literally, then C++ does not have finally, and so is not relevant. Java preceded .Net. But I doubt if the questioner knows that there are other exception processing systems, and a lose interpretation is more relevant.Herwick
H
2

Common Lisp predates C++ by a long time, and was based earlier Lisps. Java was, of course, created by Lisp men who were very aware of this. But Java is Lisp polluted by C, so they also added the checked exception specification nonsense.

Common Lisp went further and actually enabled the catch to interact with the throw routine, including to tell the throw to continue. The stack was simply not unwound until the catch was done. That meant you could throw warnings like low memory as well as throwing fails.

Herwick answered 22/7, 2019 at 0:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.