fixes #1888
This commit is contained in:
parent
b34bd3b163
commit
c6398d408d
9 changed files with 107 additions and 81 deletions
|
|
@ -5,20 +5,20 @@ discard """
|
|||
|
||||
# First variety
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
raise newException(OSError, "Problem")
|
||||
except OSError:
|
||||
for y in [1, 2, 3]:
|
||||
discard
|
||||
try:
|
||||
discard
|
||||
except EOS:
|
||||
except OSError:
|
||||
discard
|
||||
echo "1"
|
||||
|
||||
# Second Variety
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
raise newException(OSError, "Problem")
|
||||
except OSError:
|
||||
for y in [1, 2, 3]:
|
||||
discard
|
||||
for y in [1, 2, 3]:
|
||||
|
|
@ -28,8 +28,8 @@ echo "2"
|
|||
|
||||
# Third Variety
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
raise newException(OSError, "Problem")
|
||||
except OSError:
|
||||
block:
|
||||
break
|
||||
|
||||
|
|
@ -38,8 +38,8 @@ echo "3"
|
|||
# Fourth Variety
|
||||
block:
|
||||
try:
|
||||
raise newException(EOS, "Problem")
|
||||
except EOS:
|
||||
raise newException(OSError, "Problem")
|
||||
except OSError:
|
||||
break
|
||||
|
||||
echo "4"
|
||||
echo "4"
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ discard """
|
|||
# Test inheritance for exception matching:
|
||||
|
||||
try:
|
||||
raise newException(EOS, "dummy message")
|
||||
except E_Base:
|
||||
raise newException(OSError, "dummy message")
|
||||
except Exception:
|
||||
echo "caught!"
|
||||
except:
|
||||
except:
|
||||
echo "wtf!?"
|
||||
|
||||
|
||||
#OUT caught!
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,19 +8,19 @@ discard """
|
|||
var raiseEx = true
|
||||
var returnA = true
|
||||
var returnB = false
|
||||
|
||||
proc main: int =
|
||||
|
||||
proc main: int =
|
||||
try: #A
|
||||
try: #B
|
||||
if raiseEx:
|
||||
raise newException(EOS, "")
|
||||
raise newException(OSError, "")
|
||||
return 3
|
||||
finally: #B
|
||||
echo "B1"
|
||||
if returnB:
|
||||
return 2
|
||||
echo "B2"
|
||||
except EOS: #A
|
||||
except OSError: #A
|
||||
echo "catch"
|
||||
finally: #A
|
||||
echo "A1"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ discard """
|
|||
|
||||
proc test1() =
|
||||
|
||||
finally: echo "A"
|
||||
defer: echo "A"
|
||||
|
||||
try:
|
||||
raise newException(OSError, "Problem")
|
||||
|
|
@ -19,7 +19,7 @@ test1()
|
|||
|
||||
proc test2() =
|
||||
|
||||
finally: echo "B"
|
||||
defer: echo "B"
|
||||
|
||||
try:
|
||||
return
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ success'''
|
|||
"""
|
||||
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
ESomeOtherErr = object of E_Base
|
||||
ESomething = object of Exception
|
||||
ESomeOtherErr = object of Exception
|
||||
|
||||
proc genErrors(s: string) =
|
||||
if s == "error!":
|
||||
|
|
@ -17,14 +17,14 @@ proc foo() =
|
|||
var i = 0
|
||||
try:
|
||||
inc i
|
||||
onRaise(proc (e: ref E_Base): bool =
|
||||
onRaise(proc (e: ref Exception): bool =
|
||||
echo "i: ", i)
|
||||
genErrors("errssor!")
|
||||
except ESomething:
|
||||
echo("ESomething happened")
|
||||
except:
|
||||
echo("Some other error happened")
|
||||
|
||||
|
||||
# test that raise handler is gone:
|
||||
try:
|
||||
genErrors("error!")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue