Java seems to make a distinction in its terminology between “errors”, “assertions” and “exceptions.” However, there is no defined terminology (that I can see) of a conditional check and return on failure (which up to this point, I have referred to as “error checking”).
public int doSomething(int val) {
if(val < 0) return -1;
...
return 0;
}
In this example (although pointless) the method returns failure if val is negative, as a method for “error checking.” However, Java specifically defines errors as those such as RuntimeException (hardware failure, etc). So what am I referring to?
Exceptions are for exceptional conditions; things you don’t expect to happen (but are possible). Josh Bloch outlines this specifically in his book “Effective Java”.
You’ll find that many class’ methods in java return true/false (boolean) as an indicator of success/failure when failure is a common and expected condition.
With that being said, it’s never that easy. There’s definitely things in the standard java classes that throw exceptions for common conditions, etc. Overall though, the first line of this answer is how I approach my own code.