title: Java PrintWriter: Why do we handle FileNotFoundException if the file is automatically created if not found?
body: <p>In the following SSCCE, I do not get a <code>FileNotFoundException</code> even if I delete this file from the given location/path i.e. <code>"D:\\Eclipse Workspaces\\SAMPLES AND OTHER SNIPPETS\\SoapCallResults.txt"</code></p>
  
  <p>Rather the <code>PrintWriter</code> seems to create the file if it is not found. </p>
  
  <p>If the <code>Printwriter</code> creates the file if it is not found, why do we try to handle the <code>FileNotFoundException</code> (compiler complains if we don't surround it with <code>try/catch</code> or add a <code>throws</code> clause) when it is never going to be thrown?</p>
  
  <pre><code>package com.general_tests;
  
  import java.io.FileNotFoundException;
  import java.io.PrintWriter;
  
  public class PrintWriterFileNotFoundExceptionTest {
  
      public static void main(String[] args) {
          String myName = "What ever my name is!";
          PrintWriter printWriter = null;
          try {
              printWriter = new PrintWriter("D:\\Eclipse Workspaces\\SAMPLES AND OTHER SNIPPETS\\SoapCallResults.txt");
              printWriter.println(myName);
          } catch (FileNotFoundException e) {
              System.out.println("FILE NOT FOUND EXCEPTION!");
              e.printStackTrace();
          } finally {
              if (printWriter != null) { printWriter.close(); }
          }
  
      }
  
  }
  </code></pre>