objgenerator: Implement throwing exceptions out of generator.
This commit is contained in:
parent
c0abc28aa1
commit
61fd20f168
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue