Chapter 6: To Err Is Human
Mull It Over
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access