dotnet / dotnet/fsharp

Debugger should not break on f# (F sharp) exception in async blocks

Open
#5,539 3 comments 0 reactions 0 assignees View on GitHub
Area-Debug Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

The following code causes the debugger to break when the exception is thrown. Clearly the exception is handled and so the debugger should not break.

If I continue execution the program continues to run normally; printing "oops" on the screen as expected.

```fsharp
[]
let main argv =
async {
try
do! Async.Sleep(1)
failwith "oops" // The debugger breaks here but it should not as the exception is handled. It should behave like the C# version
with
| ex -> printfn "%s" (ex.Message)
}
|> Async.RunSynchronously

Console.ReadLine() |> ignore
0
```

Compare this with the equivalent C# code. This does not break when the exception is thrown. The F# version should behave the same way and not break!

```csharp
using System;
using System.Threading.Tasks;

namespace CSharpTaskException
{
class Program
{
static void Main(string[] args)
{
async Task DoSomething()
{
try
{
await Task.Delay(1);
throw new Exception("oops"); // ****** This does not cause the debugger to break as the exception is handled
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}

DoSomething().Wait();

Console.ReadLine();
}
}
}
```

_This issue has been moved from https://developercommunity.visualstudio.com/content/problem/314461/debugger-should-not-break-on-f-f-sharp-exception-i.html
VSTS ticketId: 666263_
_These are the original issue comments:_
(no comments)
_These are the original issue solutions:_
(no solutions)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.