title: Handle an exception thrown in a generator
body: <p>I've got a generator and a function that consumes it:</p>
  
  <pre><code>def read():
      while something():
          yield something_else()
  
  def process():
      for item in read():
          do stuff
  </code></pre>
  
  <p>If the generator throws an exception, I want to process that in the consumer function and then continue consuming the iterator until it's exhausted. Note that I don't want to have any exception handling code in the generator.</p>
  
  <p>I thought about something like:</p>
  
  <pre><code>reader = read()
  while True:
      try:
          item = next(reader)
      except StopIteration:
          break
      except Exception as e:
          log error
          continue
      do_stuff(item)
  </code></pre>
  
  <p>but this looks rather awkward to me. </p>