If the search fails, the function may be programmed to return −1 (or any other negative value), since this can never signify a successful result.
This has a performance advantage over the OOP style of exception handling,[4] with the drawback that negligent programmers may not check the return value, resulting in a crash when the invalid pointer is used.
A common pattern in the UNIX environment is setting a separate variable to indicate the cause of an error.
In dynamically typed languages, such as PHP and Lisp, the usual approach is to return false, none, or null when the function call fails.
For example, a numeric function normally returns a number (int or float), and while zero might be a valid response, false is not.
It works only when the original function is not meant to return a boolean value, and still requires that information about the error be conveyed via other means.
In Haskell and other functional programming languages, it is common to use a data type that is just as big as it needs to be to express any possible result.
The second case is a tagged union: a result is either some string with a descriptive error message or a successfully read character.
Further, tagged unions and option types form monads when endowed with appropriate functions: this may be used to keep the code tidy by automatically propagating unhandled error conditions.