AsyncBuilder.TryWith<'T> 方法 (F#)

在异步计算中实现 try...with。

命名空间/模块路径: Microsoft.FSharp.Control

程序集:FSharp.Core(在 FSharp.Core.dll 中)

// Signature:
member this.TryWith : Async<'T> * (exn -> Async<'T>) -> Async<'T>

// Usage:
asyncBuilder.TryWith (computation, catchHandler)

参数

  • computation
    类型:Async<'T>

    输入计算。

  • catchHandler
    类型:exn -> Async<'T>

    在 computation 引发异常时要运行的函数。

返回值

一个异步计算,它执行 computation 并在引发异常时调用 catchHandler。

备注

此函数创建一个运行 computation 并返回其结果的异步计算。 如果发生异常,则将调用 catchHandler(exn) 并改为执行生成的计算。

在执行计算时执行取消检查。 此方法的存在使得能够在 async { ... } 计算表达式语法中使用 try...with。

平台

Windows 8,Windows 7,Windows server 2012中,Windows server 2008 R2

版本信息

F#核心库版本

支持:2.0,4.0,可移植

请参见

参考

Control.AsyncBuilder 类 (F#)

Microsoft.FSharp.Control 命名空间 (F#)