tgotoexceptions7.nim 801 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. {.cast(uncheckedAssign).}:
  23. obj.kind = kindB
  24. obj.i = 2
  25. try:
  26. var objA = ObjA()
  27. bplease(ObjB(objA))
  28. except ObjectConversionDefect:
  29. echo "prevented!"
  30. try:
  31. takeRange(i)
  32. except RangeDefect:
  33. echo "caught"
  34. try:
  35. helper()
  36. except AssertionDefect:
  37. echo "AssertionDefect"
  38. echo i * i
  39. main(30)