1

Which programming language first came up with the finally block?

I ask purely out of curiosity.

It is a very useful piece of syntactic sugar, and whoever first created it surely has a very impressive grasp of solutions to programming problems.

(Note: it is deceptively difficult to find an answer to this question...)

  • 3
    Why would you call it syntactic sugar? – Pieter B Oct 1 '14 at 18:05
  • 2
    Related reading: Why is there no 'finally' construct in C++? – user22815 Oct 1 '14 at 18:06
  • @PieterB the block helps avoid duplicate code (copy pasting the statement into try and each catch block). A try-finally block helps avoid a try-catch-rethrow block which is ugly, harder to understand, and defeats the purpose of such blocks. To quote another source, everything can be accomplished without the finally block, but everything also can be accomplished on a Turing Machine. That doesn't make it good form, though. – patstuart Oct 1 '14 at 18:13
  • 1
    @PieterB because you can replace try{}finally{...} with try{}catch(e){...;throw e;} – ratchet freak Oct 1 '14 at 18:39
  • 5
    @ratchetfreak It's not that simple. ... is also executed when the try block is left via any other means: continue, break, return, and whatever other control flow statements the language offers. Of course there is still a way to replace the finally with other constructs but I think it's far beyond the threshold for syntactic sugar. – user7043 Oct 1 '14 at 19:03
9

According to wikipedia the first to introduce this was NIL.

The cleanup behavior now generally called "finally" was introduced in NIL (New Implementation of LISP) in the mid- to late-1970s as UNWIND-PROTECT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.