py/objexcept: Make mp_obj_exception_get_value support subclassed excs.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2021-06-29 17:32:18 +10:00
parent b8255dd2e0
commit e3825e28e6
2 changed files with 33 additions and 14 deletions

View File

@@ -34,6 +34,26 @@ print(MyStopIteration().value)
print(MyStopIteration(1).value)
class Iter:
def __iter__(self):
return self
def __next__(self):
# This exception will stop the "yield from", with a value of 3
raise MyStopIteration(3)
def gen():
print((yield from Iter()))
return 4
try:
next(gen())
except StopIteration as er:
print(er.args)
class MyOSError(OSError):
pass