texcas.nim 716 B

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