Handled socket exception causing force close dialog on Android device
<p>I have an android app (client) and a server app on my PC. In order to test the connection with the server, I need to open a new socket with the proper IP address and the port on which the server is listening.</p>

<p>I want my client app to have a test connection feature. The problem is: whenever I open a connection through a socket when the server is not running, the android app closes and displays the force close dialog although I do handle that exception. Why is that?</p>

<p>The app always crashes at the bottom try/catch block of the following code:</p>

<pre><code>        InetAddress serverAddr=null;
        try {
            serverAddr = InetAddress.getByName(serverIP);
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            Log.e("TCP","error 1", e);
        }
        Log.i("TCP", "C: Connecting...");
        try {
            socket = new Socket(serverAddr, serverPort);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            Log.e("TCP","error 2", e);
        }
</code></pre>

<p>Edit here is the log output:</p>

<pre><code> error 2 java.net.ConnectException: /192.168.1.101:3000 - Connection refused at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:254)
 at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:219)
 at java.net.Socket.startupSocket(Socket.java:800)
 at java.net.Socket.&lt;init&gt;(Socket.java:316)
 at com.jackusz.TCPClient.run(TCPClient.java:56)
 at java.lang.Thread.run(Thread.java:1096)
</code></pre>
