title: unreported exception UnknownHostException; must be caught or declared to be thrown
body: <p>I have a code that is given below.However when I try to compile the code I get the following error.</p>
  
  <pre><code>MyClient.java:12: error: unreported exception UnknownHostException; must be caught or declared to be thrown
      InetAddress address = InetAddress.getByName("localhost");
  </code></pre>
  
  <p>I am catching the above exception in the code.I don't know why this is happening.?</p>
  
  <pre><code>import java.io.IOException;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.lang.ClassNotFoundException;
  import java.net.InetAddress;
  import java.net.Socket;
  import java.net.UnknownHostException;
  
  public class MyClient {    
      public static void main(String[] args) {
          InetAddress address = InetAddress.getByName("localhost");
  
          int count = 0;
          try {
              /*
               * Create a connection to the server socket on the server application
               */
  
              Socket socket = new Socket(address, 9090);
  
              /*
               * Read and display the response message sent by server application
               */
  
              ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
              System.out.println("Created client socket and Input Stream Reader");
              while (true) {
                  if (count &lt; 1000) {
                      String message = (String) ois.readObject();
                      System.out.println("OFMessage: " + message);
                      count++;
                  } else {
                      break;
                  }
              }
  
              ois.close();
          } catch (UnknownHostException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (ClassNotFoundException e) {
              e.printStackTrace();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>