Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- def raisinggenfunc():
- yield 1
- raise ValueError("spurious error")
- yield 3
- def wrapper(gen):
- while True:
- try:
- value = next(gen)
- except StopIteration:
- raise
- except Exception as e:
- print(e)
- else:
- yield value
- def raiseon2(i):
- if i == 2:
- raise ValueError("spurious error")
- return i
- raisinggen = (raiseon2(i) for i in range(1, 4))
- print(list(wrapper(raisinggenfunc())))
- print(list(wrapper(raisinggen)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement