title: exceptions + signaling end-of-iterator: why is it bad in Java and normal in Python?
body: <p>I'm really confused: The standard approach in Java is to throw exceptions only in "abnormal" conditions and not to use them to signal end-of-iterator.</p>
  
  <p>examples: Effective Java, item 57 ("Use exceptions only for exceptional conditions") and <a href="http://www.javaspecialists.eu/archive/Issue162.html">JavaSpecialists newsletter 162</a>:</p>
  
  <blockquote>
    <p>Flow control</p>
    
    <p>We should never cause an exception that is otherwise preventable. I have seen code where instead of checking bounds, it is assumed that the data will be correct and then RuntimeExceptions are caught:</p>
    
    <p>Here is an example of bad code (please don't code like this):</p>
  
  <pre><code>public class Antipattern1 {
     public static void main(String[] args) {
       try {
         int i = 0;
         while (true) {
           System.out.println(args[i++]);
         }
       } catch (ArrayIndexOutOfBoundsException e) {
         // we are done
      }
    }
  }
  </code></pre>
  </blockquote>
  
  <p>whereas it <em>is</em> standard to use this idiom in Python, e.g. <a href="http://docs.python.org/library/exceptions.html#exceptions.StopIteration">StopIteration</a>:</p>
  
  <blockquote>
    <p>exception StopIteration</p>
    
    <p>Raised by an iterator‘s next() method to signal that there are no further values. This is derived from Exception rather than StandardError, since this is not considered an error in its normal application.</p>
  </blockquote>
  
  <p>Why is it bad for Java but good for Python?</p>