Advantages and disadvantages
Here are a few advantages and disadvantages that come with the Operation Result design pattern.
Advantages
It is more explicit than throwing an Exception
since the operation result type is specified explicitly as the method's return type. That makes it more evident than knowing what type of exceptions the operation and its dependencies can throw.
Another advantage is the execution speed; returning an object is faster than throwing an exception. Not that much faster, but faster nonetheless.
Disadvantages
Using operation results is more complex than throwing exceptions because we must manually propagate it up the call stack (a.k.a. returned by the callee and handled by the caller). This is especially true if the operation result must go up multiple levels, which could be an indicator not to use the pattern.
It is easy to expose members that are not used in all scenarios, creating an API surface that is bigger than needed, where some...