title: handling java exception
body: <p>This questions is related to java exceptions, why are there some cases that when an exception is thrown the program exits even though the exception was caught and there was no exit() statement?
  my code looks something like this</p>
  
  <pre><code>    void bindProxySocket(DefaultHttpClientConnection proxyConnection, String hostName, HttpParams params)
  {
      if (!proxyConnection.isOpen()) 
      {
  
          Socket socket = null;
          try {
              socket = new Socket(hostName, 80);
          } catch (UnknownHostException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          try
          {
              proxyConnection.bind(socket, params);
          }
          catch(IOException e)
          {
              System.err.println ("couldn't bind socket");
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>and then</p>
  
  <p>I call this method like this:</p>
  
  <pre><code>bindProxySocket(proxyConn, hostName, params1);
  </code></pre>
  
  <p>but, the program exits, although I want to handle the exception by doing something else, can it be because I didn't enclose the method call within a try catch clause? what happens if I catch the exception again even though it's already in the method? and what should I do if i want to clean resources in the finally clause only if an exception occurs and otherwise I want to continue with the program? I am guessing in this case I have to include the whole piece of code until I can clean the resources with in a try statement or can I do it in the handle exception statement?
  some of these questions are on this specific case, but I would like to get a thorough answer to all my questions for future reference. thanks</p>
  
  <p>edit:</p>
  
  <pre><code>java.net.UnknownHostException: www.dsewew324f.com
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.&lt;init&gt;(Unknown Source)
      at java.net.Socket.&lt;init&gt;(Unknown Source)
      at homework3.Proxy.bindProxySocket(Proxy.java:666)
      at homework3.Proxy$3.handle(Proxy.java:220)
      at org.apache.http.protocol.HttpService.doService(HttpService.java:293)
      at org.apache.http.protocol.HttpService.handleRequest(HttpService.java:212)
      at homework3.Proxy.start(Proxy.java:472)
      at homework3.Proxy.main(Proxy.java:1282)
  Exception in thread "main" java.lang.IllegalArgumentException: Socket may not be null
      at org.apache.http.impl.DefaultHttpClientConnection.bind(DefaultHttpClientConnection.java:80)
      at homework3.Proxy.bindProxySocket(Proxy.java:674)
  </code></pre>