texcpt1.nim 812 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. discard """
  2. outputsub: "-6"
  3. """
  4. type
  5. ESomething = object of Exception
  6. ESomeOtherErr = object of Exception
  7. ESomethingGen[T] = object of Exception
  8. ESomethingGenRef[T] = ref object of Exception
  9. proc genErrors(s: string) =
  10. if s == "error!":
  11. raise newException(ESomething, "Test")
  12. else:
  13. raise newException(EsomeotherErr, "bla")
  14. proc raiseBla(): int =
  15. try:
  16. genErrors("errssor!")
  17. except ESomething:
  18. echo("Error happened")
  19. except:
  20. raise
  21. proc blah(): int =
  22. try:
  23. result = raiseBla()
  24. except ESomeOtherErr:
  25. result = -6
  26. echo blah()
  27. # Issue #7845, raise generic exception
  28. var x: ref ESomethingGen[int]
  29. new(x)
  30. try:
  31. raise x
  32. except ESomethingGen[int] as e:
  33. discard
  34. try:
  35. raise new(ESomethingGenRef[int])
  36. except ESomethingGenRef[int] as e:
  37. discard
  38. except:
  39. discard