text: """Clean Code in Python - Chapter 7: Generators, Iterators, and Asynchronous Programming
  
  > yield from: send values & throw exceptions
  
  """
  from log import logger
  
  
  class CustomException(Exception):
      """A type of exception that is under control."""
  
  
  def sequence(name, start, end):
      value = start
      logger.info("%s started at %i", name, value)
      while value < end:
          try:
              received = yield value
              logger.info("%s received %r", name, received)
              value += 1
          except CustomException as e:
              logger.info("%s is handling %s", name, e)
              received = yield "OK"
      return end
  
  
  def main():
      step1 = yield from sequence("first", 0, 5)
      step2 = yield from sequence("second", step1, 10)
      return step1 + step2
  