texcas.nim 717 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. discard """
  2. targets: "c cpp"
  3. output: '''Hello
  4. Hello
  5. '''
  6. """
  7. proc test[T]() =
  8. try:
  9. raise newException(T, "Hello")
  10. except T as foobar:
  11. echo(foobar.msg)
  12. doAssert(not declared(foobar))
  13. template testTemplate(excType: typedesc) =
  14. try:
  15. raise newException(excType, "Hello")
  16. except excType as foobar:
  17. echo(foobar.msg)
  18. doAssert(not declared(foobar))
  19. proc test2() =
  20. testTemplate(Exception)
  21. doAssert(not declared(foobar))
  22. proc testTryAsExpr(i: int) =
  23. let x = try: i
  24. except ValueError as ex:
  25. echo(ex.msg)
  26. -1
  27. test[Exception]()
  28. test2()
  29. testTryAsExpr(5)
  30. # see bug #7115
  31. doAssert(not compiles(
  32. try:
  33. echo 1
  34. except [KeyError as ex1, ValueError as ex2]:
  35. echo 2
  36. ))