title: Error Handling Server 500 Errors in Java App
body: <p>I'm trying to not just use the <code>catch(Exception e) {e.printStackTrace();}</code> and give the users of the application a bit more clarity into why my application may be failing.</p>
  
  <p>Hence, I want to detect if a given server error was thrown, like Http 500 error for instance.</p>
  
  <p>Currently, my code is throwing a stack trace with:</p>
  
  <pre><code>java.io.IOException: Server returned HTTP response code: 500
  </code></pre>
  
  <p>within the catch block below:</p>
  
  <pre><code> public static void main(String args[]) {
          try {
              DOMParser parser = new DOMParser();
              String UrlToParse = "theurlishereinmycode.com";
              parser.parse(UrlToParse);
              Document doc = parser.getDocument();
  
              // Get the document's root XML node
              NodeList PGRoot = doc.getChildNodes();
  
              // Navigate down the hierarchy to get to the program node
              Node comp = getNode("ProgramGuideWCSResponse", PGRoot);
              Node PG = getNode("programGuide", comp.getChildNodes() );
              Node Programs = getNode("programs", PG.getChildNodes() );
              Node IndivdualProgram = getNode("program", Programs.getChildNodes() );
  
              //String execType = getNodeAttr("programTitle", exec);
  
              // Load the executive's data from the XML
              NodeList nodes = IndivdualProgram.getChildNodes();
              String showTitleAttr = getNodeValue("programTitle", nodes);
  
              // check to make sure the fetched Show Title isn't: 1) null or 2) blank
                  // if it is... display the default value for title.
                  // else, print the Program Title.
  
              if(showTitleAttr == null || showTitleAttr == ""){
                  System.out.println("You’re watching XX Plus");
              }
  
              else{
                  System.out.println("Program title is: " + showTitleAttr);
              }
          }
  
          catch ( Exception e ) {
              e.printStackTrace();
          }
   }
  </code></pre>
  
  <p>How can I log a HTTP 500 Error for Internal Server error?</p>
  
  <p>Thank you</p>