texception_inference.nim 661 B

123456789101112131415161718192021222324252627282930313233
  1. discard """
  2. output: '''good'''
  3. cmd: "nim c --gc:orc -d:release $file"
  4. """
  5. type
  6. Raising[T, E] = object
  7. proc foo[T, Errors](x: proc (x: Raising[T, Errors])) {.raises: Errors.} =
  8. discard
  9. proc callback(x: Raising[int, ValueError]) =
  10. echo "callback"
  11. proc xy() {.raises: [ValueError].} =
  12. foo callback
  13. proc x[E]() {.raises: [E, IOError].} =
  14. raise newException(E, "text here")
  15. try:
  16. x[ValueError]()
  17. except ValueError:
  18. echo "good"
  19. proc callback2(x: Raising[int, IOError]) =
  20. discard
  21. proc foo2[T, OtherErrors](x: proc(x: Raising[T, OtherErrors])) {.raises: [ValueError, OtherErrors].} =
  22. discard
  23. foo2 callback2