Chapter 6: To Err Is Human

Mull It Over

  1. Are return values and exceptions equivalent error reporting mechanisms? Prove it.

Return values are equivalent to global status variables because the same reason code information can be sent back by both mechanisms (although it is easier to ignore a status variable). You can write code that works in a similar manner using both of these approaches.[7]

Exceptions are a very different beast. They involve a new control flow, something very different from simple reason codes. They are tightly bound into the language and program run time. While you can simulate exceptions by hand-crafting code that propagates errors, you’d have to carefully consider:

  • How to represent errors as arbitrary objects, not just as integer ...

Get Code Craft now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.