tfinally.nim 834 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. discard """
  2. output: '''
  3. came
  4. here
  5. 3
  6. msg1
  7. msg2
  8. finally2
  9. finally1
  10. -----------
  11. except1
  12. finally1
  13. except2
  14. finally2
  15. '''
  16. """
  17. # Test return in try statement:
  18. proc main: int =
  19. try:
  20. try:
  21. return 1
  22. finally:
  23. echo("came")
  24. return 2
  25. finally:
  26. echo("here")
  27. return 3
  28. echo main() #OUT came here 3
  29. #bug 7204
  30. proc nested_finally =
  31. try:
  32. raise newException(KeyError, "msg1")
  33. except KeyError as ex:
  34. echo ex.msg
  35. try:
  36. raise newException(ValueError, "msg2")
  37. except:
  38. echo getCurrentExceptionMsg()
  39. finally:
  40. echo "finally2"
  41. finally:
  42. echo "finally1"
  43. nested_finally()
  44. echo "-----------"
  45. #bug 7414
  46. try:
  47. try:
  48. raise newException(Exception, "Hello")
  49. except:
  50. echo "except1"
  51. raise
  52. finally:
  53. echo "finally1"
  54. except:
  55. echo "except2"
  56. finally:
  57. echo "finally2"