Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
As with int.TryParse, a
function can communicate failure by sending an error code back to the
calling function via a return type or parameter. Although this can work
with simple and predictable failures, it becomes clumsy when extended to
all errors, polluting method signatures and creating unnecessary
complexity and clutter. It also cannot generalize to functions that are
not methods, such as operators (e.g., the division operator) or
properties. An alternative is to place the error in a common place where
all functions in the call stack can see it (e.g., a static method that
stores the current error per thread). This, though, requires each
function to participate in an error-propagation pattern that is
cumbersome and, ironically, itself error-prone.