← Back to context

Comment by seabass

6 days ago

I love this sort of cs history. I’m also curious—why do we “throw” an error or “raise” an exception? Why did the for loop use “for” instead of, say, “loop”?

It's been ages, but I think an earlier edition of Stroustrup's The C++ Programming Language explains that he specifically chose "throw" and "catch" because more obvious choices like "signal" were already taken by established C programs and choosing "unusual" words (like "throw" and "catch") reduced chance of collision. (C interoperability was a pretty big selling point in the early days of C++.)

  • The design of exception handling in C++ was inspired by ML, which used 'raise', and C++ might itself have used that word, were it not already the name of a function in the C standard library (as was 'signal'). The words 'throw' and 'catch' were introduced by Maclisp, which is how Stroustrup came to know of them. As he told Guy Steele at the second ACM History of Programming Languages (HOPL) conference in 1993, 'I also think I knew whatever names had been used in just about any language with exceptions, and "throw" and "catch" just were the ones I liked best.'

I'm guessing "throw" came about after someone decided to "catch" errors.

As for "raise", maybe exceptions should've been called objections.

  • "Exception" comes from hardware/state machines, and the name reflects that they may not be error cases. For instance, if an embedded device is waiting for a button press, then pressing that button will put the MCU into an exceptional/special state (eg interrupting execution or waking up from sleep).

    But surely those days are in the past. We should call them objections, because they're always used for errors and never for control flow. [1] After all, that would be an unconditional jump, and we've already settled that those are harmful.

    [1] https://docs.python.org/3/library/exceptions.html#StopIterat...

I think “raise” comes from the fact that the exception propagates “upward” through the call stack, delegating the handling of it to the next level “up.” “Throw” may have to do with the idea of not knowing what to do/how to handle an error case, so you just throw it away (or throw your hands up in frustration xD). Totally just guessing

  • I suspect it comes from raising flags/signals (literally as one might run a flag up a flag pole?) to indicates CPU conditions, and then that terminology getting propagated from hw to sw.

    • Sounds plausuble. Some of the earliest exception handling systems did not have any semantic difference between CPU exceptions and software exceptions.

      1 reply →

    • … which could come from raising the voltage of a signal indicating a condition.

    • I would have thought it came from the concept of 'raising an issue' or even 'raising a stink'.

    • idk because there are some circles in which boolean variables are called flags but I've never seen them referred to as being raised or unraised/lowered, only set and unset

You throw something catchable and if you fail to catch it it’ll break. Unless it’s a steel ball.

You raise flags or issues, which are good descriptions of an exception.

That's a great question. The first language I learned was python, and "for i in range(10)" makes a lot of sense to me. But "for (int i = 0; i < 10; i++)" must have come first, and in that case "for" is a less obvious choice.

  • BASIC had the FOR-NEXT loop back in 1964.

    10 FOR N = 1 TO 10

    20 PRINT " ";

    30 NEXT N

    C language would first release in 1972, that had the three-part `for` with assignment, condition, and increment parts.

  • FOR comes from ALGOL in which as far as I know is was spelled:

        for p := x step d until n do

"For" for loop statements fits with math jargon: "for every integer i in the set [1:20], ..."