From: David ‘Bombe’ Roden Date: Wed, 18 Mar 2009 23:46:05 +0000 (+0100) Subject: Add try-finally block to ensure removal of FCP listener. X-Git-Tag: v0.1.1~92 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=84da1f5f1d0169235d1c71991f62af5e08c7263f;p=jFCPlib.git Add try-finally block to ensure removal of FCP listener. --- diff --git a/src/net/pterodactylus/fcp/highlevel/FcpClient.java b/src/net/pterodactylus/fcp/highlevel/FcpClient.java index bcf529b..21dc647 100644 --- a/src/net/pterodactylus/fcp/highlevel/FcpClient.java +++ b/src/net/pterodactylus/fcp/highlevel/FcpClient.java @@ -142,18 +142,21 @@ public class FcpClient { } }; fcpConnection.addFcpListener(fcpListener); - fcpConnection.connect(); - ClientHello clientHello = new ClientHello(name); - fcpConnection.sendMessage(clientHello); - while (true) { - try { - fcpListener.complete(); - break; - } catch (InterruptedException e) { - /* ignore, we’ll loop. */ + try { + fcpConnection.connect(); + ClientHello clientHello = new ClientHello(name); + fcpConnection.sendMessage(clientHello); + while (true) { + try { + fcpListener.complete(); + break; + } catch (InterruptedException e) { + /* ignore, we’ll loop. */ + } } + } finally { + fcpConnection.removeFcpListener(fcpListener); } - fcpConnection.removeFcpListener(fcpListener); if (fcpListener.getFcpException() != null) { throw fcpListener.getFcpException(); }