tfinally4.nim 810 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. output: "B1\nA1\n1\nB1\nB2\ncatch\nA1\n1\nB1\nA1\nA2\n2\nB1\nB2\ncatch\nA1\nA2\n0\nB1\nA1\n1\nB1\nB2\nA1\n1\nB1\nA1\nA2\n2\nB1\nB2\nA1\nA2\n3"
  3. """
  4. # More thorough test of return-in-finaly
  5. var raiseEx = true
  6. var returnA = true
  7. var returnB = false
  8. proc main: int =
  9. try: #A
  10. try: #B
  11. if raiseEx:
  12. raise newException(OSError, "")
  13. return 3
  14. finally: #B
  15. echo "B1"
  16. if returnB:
  17. return 2
  18. echo "B2"
  19. except OSError: #A
  20. echo "catch"
  21. finally: #A
  22. echo "A1"
  23. if returnA:
  24. return 1
  25. echo "A2"
  26. for x in [true, false]:
  27. for y in [true, false]:
  28. for z in [true, false]:
  29. # echo "raiseEx: " & $x
  30. # echo "returnA: " & $y
  31. # echo "returnB: " & $z
  32. raiseEx = x
  33. returnA = y
  34. returnB = z
  35. echo main()