title: How to do unit test for Exceptions?
body: <p>As you know, exception is thrown at the condition of abnormal scenarios. So how to analog these exceptions? I feel it is challenge. For such code snippets:</p>
  
  <pre><code>public String getServerName() {
      try {
  
          InetAddress addr = InetAddress.getLocalHost();
          String hostname = addr.getHostName();
          return hostname;
      }
      catch (Exception e) {
          e.printStackTrace();
          return "";
      }
  }
  </code></pre>
  
  <p>Does anybody have good ideas?</p>