Sorry for question, but I'm totally noob in Java. What is the best practice to execute ServerSocket.close()
when caught IOException
from ServerSocket
? According to docs, ServerSocket.close()
throws IOException
and compiler asks us to catch it. What is the proper way to close connection on IOException
?
try {
server = new ServerSocket(this.getServerPort());
while(true) {
socket = server.accept();
new Handler( socket );
}
} catch (IOException e) {
if (server != null && !server.isClosed()) {
server.close(); //compiler do not allow me to do because I should catch IOExceoption from this method also...
}
}
Thank you!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…