Exception Handling

Exception handling is another one of those concepts that seems less important when you’re writing code for a course, but becomes crucial in production code. Languages vary quite a bit in the tools they provide for exception handling – for example, the general approach taken by Java, C++, Ruby, and Python is syntactically noisier and, arguably, less semantically orthogonal than Go’s approach; Haskell (which we won’t talk much about today) lets the programmer build error handling into the types, so that the program logic code is completely separate from the error handling code.

The first of the following three sections discuss exception handling in Java, C++, and Ruby, resp.; the fourth section gives an overview of alternative means of handling errors and primarily focuses on Go. Whenever you see the word Exercise, you should complete the corresponding task – be sure to questions if you get stuck on anything! Get out a piece of paper, because there are a few places where you’ll be asked to write something down for class participation.

  1. Java
  2. C++
  3. Ruby
  4. Alternatives

Be sure to turn in your group’s paper at the end to get your participation points!