title: Thread.sleep inside infinite while loop in lambda doesn't require 'catch (InterruptedException)' - why not?
body: <p>My question is about <code>InterruptedException</code>, which is thrown from the <code>Thread.sleep</code> method. While working with <code>ExecutorService</code> I noticed some weird behaviour that I don't understand; here is what I mean:</p>
  
  <pre><code>ExecutorService executor = Executors.newSingleThreadExecutor();
      executor.submit(() -&gt; {
          while(true)
          {
              //DO SOMETHING
              Thread.sleep(5000);
          }
      });
  </code></pre>
  
  <p>With this code, the compiler doesn't give me any error or message that <code>InterruptedException</code> from <code>Thread.sleep</code> should be caught. But when I am trying to change the loop condition and replace "true" with some variable like this:</p>
  
  <pre><code>ExecutorService executor = Executors.newSingleThreadExecutor();
      executor.submit(() -&gt; {
          while(tasksObserving)
          {
              //DO SOMETHING
              Thread.sleep(5000);
          }
      });
  </code></pre>
  
  <p>The compiler constantly complains that <code>InterruptedException</code> has to be handled. Can someone explain to me why this happens, and why if the condition is set to true the compiler ignores the InterruptedException?</p>