#[
autogenerated by docgen
loc: /build/nim/src/nim/lib/js/asyncjs.nim(251, 21)
rdoccmd: -r:off
]#
import std/assertions
import "/build/nim/src/nim/lib/js/asyncjs.nim"
{.line: ("/build/nim/src/nim/lib/js/asyncjs.nim", 251, 21).}:
  from std/sugar import `=>`
  from std/strutils import contains

  proc fn(n: int): Future[int] {.async.} =
    if n >= 7: raise newException(ValueError, "foobar: " & $n)
    else: result = n * 2

  proc main() {.async.} =
    var reason: Error
    await fn(6).catch((r: Error) => (reason = r)) # note: `()` are needed, `=> reason = r` would not work
    assert reason == nil
    await fn(7).catch((r: Error) => (reason = r))
    assert reason != nil
    assert  "foobar: 7" in $reason.message

  discard main()

