mercredi 14 août 2019

Is the try and catch considered one statement after an if?

if (instance != null)
  try (InputStream stream = new FileInputStream(file)) {
    instance = getInstance(stream);
    instance.sourceFile = file;
    instances.put(instance.sourceFile.getPath(), instance);
    return instance;
  } catch (Exception e) {
    throw new RuntimeException("Cannot locate '" + file + "'. " + e, e);
  }
return instance;

Came across this in the codebase and wondering if the if applies to the entire try/catch or if it is being ignored. If the if is being applied to the entire try/catch I want to wrap it with curly braces but I don't want to break anything and I can't test it.

Aucun commentaire:

Enregistrer un commentaire