From cb912e039b3db0c41c518910fcce6df4e50eeb69 Mon Sep 17 00:00:00 2001 From: Valentin Spiroski Date: Mon, 5 Feb 2024 15:25:53 +0100 Subject: [PATCH] refactoring: comments in catch, finally in run() --- src/main/java/ClientHandler.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/ClientHandler.java b/src/main/java/ClientHandler.java index b6ae287..5d943af 100644 --- a/src/main/java/ClientHandler.java +++ b/src/main/java/ClientHandler.java @@ -32,17 +32,17 @@ public class ClientHandler implements Runnable { // Broadcast the client's message to all connected clients chatServer.broadcastMessage(name + ": " + message); message = fromClientReader.readLine(); - } + } } catch (IOException e) { - throw new RuntimeException(e); + throw new RuntimeException(e); // Handle exceptions by throwing a runtime exception } - finally { //chatServer.removeClient(this); - chatServer.broadcastMessage(name + " disconnected."); - + chatServer.broadcastMessage(name + " disconnected."); // Broadcast a message when the client is disconnected + + // Close resources in the finally block if (fromClientReader != null) { try { fromClientReader.close(); @@ -54,7 +54,7 @@ public class ClientHandler implements Runnable { if (toClientWriter != null) { toClientWriter.close(); } - } + } } public void sendMessage(String message) {