That check is repeated quite a lot of times. Can we extract a method? + probably we should log something as an addition to an exception.