tgotoexceptions4.nim 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. discard """
  2. cmd: "nim c --gc:arc --exceptions:goto $file"
  3. output: '''caught in gun
  4. caught in fun
  5. caughtsome msgMyExcept
  6. in finally
  7. caught1
  8. 123
  9. 123'''
  10. """
  11. when true:
  12. # bug #13070
  13. type MyExcept = object of CatchableError
  14. proc gun() =
  15. try:
  16. raise newException(MyExcept, "some msg")
  17. except Exception as eab:
  18. echo "caught in gun"
  19. raise eab
  20. proc fun() =
  21. try:
  22. gun()
  23. except Exception as e:
  24. echo "caught in fun"
  25. echo("caught", e.msg, e.name)
  26. finally:
  27. echo "in finally"
  28. fun()
  29. when true:
  30. # bug #13072
  31. type MyExceptB = object of CatchableError
  32. proc gunB() =
  33. raise newException(MyExceptB, "some msg")
  34. proc funB() =
  35. try:
  36. gunB()
  37. except CatchableError:
  38. echo "caught1"
  39. funB()
  40. # bug #13782
  41. import strutils
  42. var n = 123
  43. try: n = parseInt("xxx")
  44. except: discard
  45. echo n
  46. proc sameTestButForLocalVar =
  47. var n = 123
  48. try: n = parseInt("xxx")
  49. except: discard
  50. echo n
  51. sameTestButForLocalVar()