Automatic exception wrapper in java
This looks like something Optionals can handle, so:

public static Optional&lt;Object&gt; getById(int id) {
    for(Object thing : things) {
        if(thing.getId() == id) {
            return Optional.of(thing);
        }
    }

    return Optional.empty();
}


Now in your read code, you can simply do this:

public static void read(DataInputStream stream) throws IOException {
    Object thing = getById(stream.readInt())
                       .orElseThrow(() -&gt; new IOException("Could not find Id"));

    // Do something with thing
}