tfinally4.nim 782 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. discard """
  2. output: '''
  3. B1
  4. A1
  5. 1
  6. B1
  7. B2
  8. catch
  9. A1
  10. 1
  11. B1
  12. A1
  13. A2
  14. 2
  15. B1
  16. B2
  17. catch
  18. A1
  19. A2
  20. 0
  21. B1
  22. A1
  23. 1
  24. B1
  25. B2
  26. A1
  27. 1
  28. B1
  29. A1
  30. A2
  31. 2
  32. B1
  33. B2
  34. A1
  35. A2
  36. 3'''
  37. """
  38. # More thorough test of return-in-finaly
  39. var raiseEx = true
  40. var returnA = true
  41. var returnB = false
  42. proc main: int =
  43. try: #A
  44. try: #B
  45. if raiseEx:
  46. raise newException(OSError, "")
  47. return 3
  48. finally: #B
  49. echo "B1"
  50. if returnB:
  51. return 2
  52. echo "B2"
  53. except OSError: #A
  54. echo "catch"
  55. finally: #A
  56. echo "A1"
  57. if returnA:
  58. return 1
  59. echo "A2"
  60. for x in [true, false]:
  61. for y in [true, false]:
  62. for z in [true, false]:
  63. # echo "raiseEx: " & $x
  64. # echo "returnA: " & $y
  65. # echo "returnB: " & $z
  66. raiseEx = x
  67. returnA = y
  68. returnB = z
  69. echo main()