mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-03 05:54:33 +00:00
Update exception.er
This commit is contained in:
parent
395ca6e595
commit
74f3bad52e
1 changed files with 11 additions and 4 deletions
|
@ -2,14 +2,21 @@ unsound = import "unsound"
|
||||||
|
|
||||||
# TODO: exception: Exception
|
# TODO: exception: Exception
|
||||||
unsound.pyexec("""
|
unsound.pyexec("""
|
||||||
def try_(p, exc=lambda _: None):
|
def try_(p, exc=lambda _: None, els=lambda: None, fin=lambda: None):
|
||||||
try:
|
try:
|
||||||
return p()
|
res = p()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return exc(e)
|
res = exc(e)
|
||||||
|
else:
|
||||||
|
els()
|
||||||
|
finally:
|
||||||
|
fin()
|
||||||
|
return res
|
||||||
""")
|
""")
|
||||||
.try! = unsound.pyeval("try_")
|
.try! = unsound.pyeval("try_")
|
||||||
assert .try! in |T, U|(
|
assert .try! in |T, U|(
|
||||||
p!: () => T,
|
p!: () => T,
|
||||||
exc!: (exception: Obj) => U := (exception: Obj) => NoneType
|
exc!: (exception: Obj) => U := (exception: Obj) => NoneType,
|
||||||
|
else! := () => NoneType,
|
||||||
|
finally! := () => NoneType,
|
||||||
) => T or U
|
) => T or U
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue