mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-27 19:59:07 +00:00
23 lines
540 B
Python
23 lines
540 B
Python
unsound = import "unsound"
|
|
|
|
# TODO: exception: Exception
|
|
unsound.pyexec("""
|
|
def try_(p, exc=lambda _: None, els=lambda: None, fin=lambda: None):
|
|
__result = None
|
|
try:
|
|
__result = p()
|
|
except Exception as e:
|
|
__result = exc(e)
|
|
else:
|
|
els()
|
|
finally:
|
|
fin()
|
|
return __result
|
|
""")
|
|
.try! = unsound.pyeval("try_")
|
|
assert .try! in |T, U|(
|
|
p!: () => T,
|
|
exc!: (exception: Obj) => U := (exception: Obj) => NoneType,
|
|
else! := () => NoneType,
|
|
finally! := () => NoneType,
|
|
) => T or U
|