0

I have some files to be read in the project (icon and font) but, because they are directly in the project, I believe that I will not have IOException or FontFormatException.

For now I have this code snippet:

getClass().getResourceAsStream("/fonts/Sticky Notes.ttf")
try {
    _main.createNewNote();
} catch (IOException | FontFormatException ignored) { //never be called}

Is this ok or should I do it better? And how to do better?

PS:"THROWS" in the method declaration is bad in these cases?

geocodezip
  • 158,664
  • 13
  • 220
  • 245

1 Answers1

0

You can wrap it into some runtime exception.

try {
    _main.createNewNote();
} catch (IOException | FontFormatException e) { 
    throw new IllegalStateException(e.getMessage(), e);
}

But you mustn't leave catch clause empty. If you declare throws on this method, you will need to handle this exception when you call this method. So I'd prefer to rethrow it.