Commit 61fd20f1 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

objgenerator: Implement throwing exceptions out of generator.

parent c0abc28a
......@@ -103,8 +103,10 @@ STATIC mp_obj_t gen_next_send(mp_obj_t self_in, mp_obj_t send_value) {
return *self->sp;
case MP_VM_RETURN_EXCEPTION:
self->ip = 0;
nlr_jump(self->state[self->n_state - 1]);
default:
// TODO
assert(0);
return mp_const_none;
}
......
......@@ -9,3 +9,23 @@ def gen():
for i in gen():
print(i)
# Test throwing exceptions out of generator
def gen2():
yield 1
raise ValueError
yield 2
yield 3
g = gen2()
print(next(g))
try:
print(next(g))
except ValueError:
print("ValueError")
try:
print(next(g))
except StopIteration:
print("StopIteration")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment