Pages

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 {
        try
            failwith "error"
        with
            | :? ArgumentException as e -> printfn "exception... :( "
            | :? Exception as e -> printfn "handled anyway"
        }

asyncOperationWithExcpetion |> Async.Start

System.Threading.Thread.Sleep(1*1000)

printfn "aa"  //put break point here!



1 comment:

Anonymous said...

Thanks! This just helped me. :)