mirror of
https://github.com/erg-lang/erg.git
synced 2025-07-12 15:45:22 +00:00
22 lines
531 B
Python
22 lines
531 B
Python
unsound = import "unsound"
|
|
|
|
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: BaseException) => U := (exception: BaseException) => NoneType,
|
|
else! := () => NoneType,
|
|
finally! := () => NoneType,
|
|
) => T or U
|