title: How to cleanly deal with "unreported exception IOException" in stream/forEach?
body: <p>I'm trying to write to a file using Java Streams. To my knowledge you don't have to catch an exception as long as you throw it forward.
  The compiler however throws an error (on the line of the stream.foreach()...) and says</p>
  
  <blockquote>
    <p>error: unreported exception IOException; must be caught or declared to be thrown</p>
  </blockquote>
  
  <p>Could someone explain why this is? 
  (I'm only interested in solutions using streams)</p>
  
  <pre><code>public void save(String file, ArrayList&lt;String&gt; text) throws IOException {
      FileWriter fw = new FileWriter(file);
      text.stream().forEach(x-&gt;fw.write(x +"\n"));
      fw.close();
  }
  </code></pre>
  
  <p>Netbeans suggests this, but is there a shorter way?</p>
  
  <pre><code>public void save(String file, ArrayList&lt;String&gt; text) throws IOException {
      FileWriter fw = new FileWriter(file);
      text.stream().forEach(x-&gt;{
          try {
              fw.write(x +"\n");
          } catch (IOException ex) {
              ...
          }
      });
      fw.close();
  }
  </code></pre>