Since Java support exception, I thought an EOFException would be thrown when trying reading a byte at the end of an input stream, like
byte read() throws EOFException, IOException
But in fact InputStream#read returns
the next byte of data, or -1 if the end of the stream is reached.
which reminds me about getchar in C. But on the other hand it throws
IOException: if an I/O error occurs.
Why is it designed in such way?
A lot of the early APIs were less than desirable and there is plenty of discussion in which the designers wish they could have done it different.
I would speculate that this is not one of those cases. Throwing an “EOFException” would probably encourage programmers to
tryto read until an exception is caught. Meaning exception handling would be used as a way of controlling program logic which is referred to as the exception handling antipattern