hel*_*igo 2 java comments exception
我有下一个代码:
InputStream is = new FileInputStream("test.txt");
// do something
try {
is.close();
} catch(IOException ex) {
// do nothing
// or
// NOP
// or something else?
}
Run Code Online (Sandbox Code Playgroud)
问题是Java世界中是否有任何约定可以告诉您什么都不做?就像在我的情况下,如果无法关闭InputStream,我想什么都不做."NOP"评论是否可以接受?它来自Assembler,意思是"无操作".
try {
...
} catch (IOException ignored) {}
Run Code Online (Sandbox Code Playgroud)
完整,清晰,简洁.
但你应该使用像Apache Commons IOIOUtils.closeQuietly(InputStream)
这样的东西.