-
I found that any exception raised from generator ends with StopIteration at next next() call. So, the solution wasn't able to provide bulletproof solution for unexpected errors. This solution uses some other nice-to-look-at shortcut to not duplicate code that is based on closures. I'm able to protect in-out boxes against unexpected errors. I'm not able to do the same for out-only boxes based on generators, but it is better than nothing. Boxes generating messages should know what they are doing, so they shouldn't need so much effort.
d16bbc90