Multiple exception idents in except for async. Ref #1487.
This commit is contained in:
parent
952de51170
commit
6689fa68f5
3 changed files with 91 additions and 25 deletions
|
|
@ -1,5 +1,5 @@
|
|||
discard """
|
||||
file: "tasyncexceptions.nim"
|
||||
file: "tasyncfile.nim"
|
||||
exitcode: 0
|
||||
"""
|
||||
import asyncfile, asyncdispatch, os
|
||||
|
|
|
|||
51
tests/async/tasynctry.nim
Normal file
51
tests/async/tasynctry.nim
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
discard """
|
||||
file: "tasynctry.nim"
|
||||
exitcode: 0
|
||||
output: '''
|
||||
Generic except
|
||||
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")
|
||||
|
||||
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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue