title: What happens when a coroutine raises an exception?
body: <p>I'm not sure what exactly happens in the following piece of code:</p>
  
  <pre><code>def coroutine():
      lst = []
      try:
          while True:
              item = (yield lst)
              if item == 3:
                  raise ValueError
              print('append {}'.format(item))
              lst.append(item)
      except GeneratorExit:
          print('GeneratorExit')
  
  crt = coroutine()
  
  next(crt)
  print(crt.send(1))
  print(crt.send(2))
  
  try:
      print(crt.send(3))
  except ValueError:
      pass
  
  print(crt.send(4))
  </code></pre>
  
  <p>This outputs:</p>
  
  <pre><code>append 1
  [1]
  append 2
  [1, 2]
  
  Traceback (most recent call last):
    File "D:\Documents and Settings\Brecht\Desktop\crt.py", line 25, in &lt;module&gt;
      print(crt.send(4))
  StopIteration
  </code></pre>
  
  <p>When stepping through the code with a debugger, on <code>raise ValueError</code>, execution jumps to <code>except GeneratorExit:</code>, but the body of this except clause is not executed ('GeneratorExit' is not printed). Why not?</p>
  
  <p>Aside from that, I don't suppose I can in any way resume the coroutine after it has thrown an exception? Is there any particular reason not to allow this? This would be useful at least in my particular use case :)</p>