summary refs log tree commit diff stats
path: root/tests/async/tasynctry.nim
blob: 66ea40d4983f581bc572c7074805e7dd6393edf2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
discard """
  file: "tasynctry.nim"
  exitcode: 0
  output: '''
Generic except: Test
Specific except
Multiple idents in except
Multiple except branches
Multiple except branches 2
'''
"""
import asyncdispatch

# Here we are testing the ability to catch exceptions.

proc foobar() {.async.} =
  if 5 == 5:
    raise newException(EInvalidIndex, "Test")

proc catch() {.async.} =
  # TODO: Create a test for when exceptions are not caught.
  try:
    await foobar()
  except:
    echo("Generic except: ", getCurrentExceptionMsg())

  try:
    await foobar()
  except EInvalidIndex:
    echo("Specific except")

  try:
    await foobar()
  except OSError, EInvalidField, EInvalidIndex:
    echo("Multiple idents in except")

  try:
    await foobar()
  except OSError, EInvalidField:
    assert false
  except EInvalidIndex:
    echo("Multiple except branches")

  try:
    await foobar()
  except EInvalidIndex:
    echo("Multiple except branches 2")
  except OSError, EInvalidField:
    assert false

asyncCheck catch()