tgotoexceptions8.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. discard """
  2. output: '''A
  3. B
  4. X
  5. inner finally
  6. Y
  7. outer finally
  8. msg1
  9. msg2
  10. finally2
  11. finally1
  12. true'''
  13. cmd: "nim c --gc:arc $file"
  14. """
  15. # bug #13668
  16. proc main =
  17. try:
  18. try:
  19. raise newException(IOError, "IOError")
  20. except:
  21. echo "A"
  22. raise newException(CatchableError, "CatchableError")
  23. except:
  24. echo "B"
  25. #discard
  26. proc mainB =
  27. try:
  28. try:
  29. raise newException(IOError, "IOError")
  30. except:
  31. echo "X"
  32. raise newException(CatchableError, "CatchableError")
  33. finally:
  34. echo "inner finally"
  35. except:
  36. echo "Y"
  37. #discard
  38. finally:
  39. echo "outer finally"
  40. main()
  41. mainB()
  42. when true:
  43. #bug 7204
  44. proc nested_finally =
  45. try:
  46. raise newException(KeyError, "msg1")
  47. except KeyError as ex:
  48. echo ex.msg
  49. try:
  50. # pop exception
  51. raise newException(ValueError, "msg2") # push: exception stack (1 entry)
  52. except:
  53. echo getCurrentExceptionMsg()
  54. # pop exception (except)
  55. finally:
  56. echo "finally2"
  57. # pop exception (except KeyError as ex)
  58. finally:
  59. echo "finally1"
  60. nested_finally()
  61. # bug #14925
  62. proc test(b: bool) =
  63. echo b
  64. test(try: true except: false)