Files
Nim/tests/exception/tfinally4.nim
Andreas Rumpf c3344862b0 --exception:goto switch for deterministic exception handling (#12977)
This implements "deterministic" exception handling for Nim based on goto instead of setjmp. This means raising an exception is much cheaper than in C++'s table based implementations. Supports hard realtime systems. Default for --gc:arc and the C target because it's generally a good idea and arc is all about deterministic behavior.

Note: This implies that fatal runtime traps are not catchable anymore! This needs to be documented.
2020-01-01 10:01:49 +01:00

74 lines
782 B
Nim

discard """
output: '''
B1
A1
1
B1
B2
catch
A1
1
B1
A1
A2
2
B1
B2
catch
A1
A2
0
B1
A1
1
B1
B2
A1
1
B1
A1
A2
2
B1
B2
A1
A2
3'''
"""
# More thorough test of return-in-finaly
var raiseEx = true
var returnA = true
var returnB = false
proc main: int =
try: #A
try: #B
if raiseEx:
raise newException(OSError, "")
return 3
finally: #B
echo "B1"
if returnB:
return 2
echo "B2"
except OSError: #A
echo "catch"
finally: #A
echo "A1"
if returnA:
return 1
echo "A2"
for x in [true, false]:
for y in [true, false]:
for z in [true, false]:
# echo "raiseEx: " & $x
# echo "returnA: " & $y
# echo "returnB: " & $z
raiseEx = x
returnA = y
returnB = z
echo main()