title: StopIteration in Python
body: <p>I encounter a problem while reading functional programming python.</p>
  
  <pre><code>def get_log_lines(log_file): 
      line = read_line(log_file) 
      while True:
          try:
              if complex_condition(line):
                  yield line
              line = read_line(log_file)
          except StopIteration:
              raise
  </code></pre>
  
  <p>A <code>try...except</code> statement is added to surround the <code>read_line</code>. Why not just let <code>read_line</code> throw the <code>StopIteration</code> exception like this:</p>
  
  <pre><code>def get_log_lines(log_file): 
      line = read_line(log_file) 
      while True:
          if complex_condition(line):
              yield line
          line = read_line(log_file)
  </code></pre>