One way is to use Async.Catch in the call workflow. Given a couple of functions (an "asynchronous" function and something to work with the result):
let work a = async { return match a with | 1 -> "Success!" | _ -> failwith "Darnit" } let printResult (res:Choice<'a,System.Exception>) = match res with | Choice1Of2 a -> printfn "%A" a | Choice2Of2 e -> printfn "Exception: %s" e.Message
One can use Async.Catch
let callingWorkflow = async { let result = work 1 |> Async.Catch let result2 = work 0 |> Async.Catch [ result; result2 ] |> Async.Parallel |> Async.RunSynchronously |> Array.iter printResult } callingWorkflow |> Async.RunSynchronously
Async.Catch returns a Choice<'T1,'T2> . Choice1Of2 for success and exception thrown for Choice2Of2 .
source share