tgotoexceptions7.nim 770 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. discard """
  2. cmd: "nim c --gc:arc --exceptions:goto --panics:off $file"
  3. output: '''prevented!
  4. caught
  5. AssertionDefect
  6. 900'''
  7. """
  8. type
  9. E = enum
  10. kindA, kindB
  11. Obj = object
  12. case kind: E
  13. of kindA: s: string
  14. of kindB: i: int
  15. ObjA = ref object of RootObj
  16. ObjB = ref object of ObjA
  17. proc takeRange(x: range[0..4]) = discard
  18. proc bplease(x: ObjB) = discard
  19. proc helper = doAssert(false)
  20. proc main(i: int) =
  21. var obj = Obj(kind: kindA, s: "abc")
  22. obj.kind = kindB
  23. obj.i = 2
  24. try:
  25. var objA = ObjA()
  26. bplease(ObjB(objA))
  27. except ObjectConversionDefect:
  28. echo "prevented!"
  29. try:
  30. takeRange(i)
  31. except RangeDefect:
  32. echo "caught"
  33. try:
  34. helper()
  35. except AssertionDefect:
  36. echo "AssertionDefect"
  37. echo i * i
  38. main(30)