Frontier Software

Error Handling

Handling errors in concurrent programs involves a completely different way of thinking than handling errors in sequential programs… Error handling in concurrent Erlang programs is based on the idea of remote detection and handling of errors. Instead of handling an error in the process where the error occurs, we let the process die and correct the error in some other process. — Joe Armstrong in Programming Erlang.

5 Error Handling strategies

  1. Propogate the error (ie Erlang-style).
  2. Retry if error is due to a transient problem, possibly with a delay and limit on number of attempts.
  3. Print error and stop program (usually reserved for main package).
  4. Log error and continue.
  5. Ignore error entirely.

Error handling in Go has a particular rhythm. After checking an error, failure is usually dealt with before success. If failure causes the function to return, the logic for success is not indented within an else block but follows at the outer level. — gopl

A function for which failure is an expected behaviour returns and additional result, conventionally the last one… nil implies success and non-nil implies failure, and that a non-nil error has an error message string which we can obtain by calling its Error method or print. — gopl