Wednesday, May 9, 2012

Debug Async F# try..catch statement

Look at the following code. When you try to debug it, the behavior seems odd when you see a dialog popup telling you the exception is not handled by user code. You might just wondering I put the :? Exception there and even get a warning say all the exception is handled. The trick is to go to Tools->Options->Debug settings and turn off "Just my code".

The dialog says unhandled by user code, the exception is handled by F# library code which is not user code.

module File1

open System

let asyncOperationWithExcpetion =
    async {
            failwith "error"
            | :? ArgumentException as e -> printfn "exception... :( "
            | :? Exception as e -> printfn "handled anyway"

asyncOperationWithExcpetion |> Async.Start


printfn "aa"  //put break point here!

1 comment:

openid said...

Thanks! This just helped me. :)