I have the following piece of code.
Path path = Paths.get(file.getAbsolutePath());
ByteArrayResource resource = null;
try {
resource = new ByteArrayResource(Files.readAllBytes(path));
} catch (IOException e) {
// DEAD CODE.
// file existance is checked by resource manager
}
Is there a better way to handle the dead catch? The "file" variable is loaded by a resource manager, that already handle the case of a file not found (by throwing an exception itself). This is "dead code" only because of application logic, if it was not for the manager doing the check, this would have not been "dead code".
The alternative I can think of, is to create a custom DeadCodeException() (extending RuntimeException()) and throw it whenever a case like this appear. This would not cause a NullPointerException() on "resource", in case in the future the manager logic changes.
How can I handle this case using good code standards?
Edit:
Thank you everyone. Apparently I made a mistake here. As @GenerousBadger and @RandomCoder_01 have remarked, IOExceptionI() is not a FileNotFoundException(), so it can still be thrown given the right (wrong?) circustances.
I will use AssertionError() in similar situations, by as for this one, I have to handle the exception.