Hi Raffaello,
Exceptions related to the arguments should be highest priority so they are
not obscured by any more dynamic state related to the stream.
There's no specific order between checks of the arguments,
though in this case the NPE would naturally occur before IOOBE.
There are more complex cases where some arguments are not used
or used conditionally where the checks become dependent on the dynamic
state.
$.02, Roger
On 6/23/20 10:34 AM, Raffaello Giulietti wrote:
Hi,
the InputStream.read(byte[], int, int) method [1] can throw
* IOException
* NullPointerException
* IndexOutOfBoundsException
Is there a recommended priority for the conditions associated to the
exceptions to be checked? For example, if the arguments are invalid
and the stream is already closed, which exception shall be thrown?
Greetings
Raffaello
----
[1]
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/io/InputStream.html#read(byte%5B%5D,int,int)