mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +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
|
||||
unsound.pyexec("""
|
||||
def try_(p, exc=lambda _: None):
|
||||
def try_(p, exc=lambda _: None, els=lambda: None, fin=lambda: None):
|
||||
try:
|
||||
return p()
|
||||
res = p()
|
||||
except Exception as e:
|
||||
return exc(e)
|
||||
res = exc(e)
|
||||
else:
|
||||
els()
|
||||
finally:
|
||||
fin()
|
||||
return res
|
||||
""")
|
||||
.try! = unsound.pyeval("try_")
|
||||
assert .try! in |T, U|(
|
||||
p!: () => T,
|
||||
exc!: (exception: Obj) => U := (exception: Obj) => NoneType
|
||||
exc!: (exception: Obj) => U := (exception: Obj) => NoneType,
|
||||
else! := () => NoneType,
|
||||
finally! := () => NoneType,
|
||||
) => T or U
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue