An in-band error indicator is a type returned by a function that can indicate either a legitimate return value , or an illegitimate value that indicates an error of some sort. Some common examples of in-band error indicators include:
- A valid object or
null
- An integer indicating a positive value, or -1 −1 to indicate that an error occurred
- An array of valid objects or
null
indicating the absence of valid objects. (This topic is further addressed in MET55-JG. For methods that return an array or collection prefer returning an empty array or collection over a null value.)
In-band - error indicators require checking for the error; however, this checking is often overlooked. Failure to check for such error conditions not only violates EXP00-J. Do not ignore values returned by methods, but also has the unfortunate effect of propagating invalid values that may subsequently be treated as valid in later computations.
...
Returning an object that might be null on failure or a valid object on success is a common example of in-band error indicator. While there are often Although better function designs are often available, returning an object that may be null can be acceptable under some circumstances. See 26. MET54-JG. Always provide feedback about the resulting value of a method for an example.
...