© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
79 replies
qqdev

❔ This is not a .NET bug, right? (async void)

Hi! Is this by design?
using System;
using System.Threading.Tasks;

public class Program
{
    public static void Main()
    {
        DoStuff();
    }

    private static async void DoStuff()
    {
        try
        {
            await DoAsyncStuff();
        }
        catch
        {
            Console.WriteLine("catch");
        }
        finally
        {
            Console.WriteLine("finally");
        }
    }

    private static async Task DoAsyncStuff()
    {
        await Task.Delay(1);
        throw new Exception();
    }
}
using System;
using System.Threading.Tasks;

public class Program
{
    public static void Main()
    {
        DoStuff();
    }

    private static async void DoStuff()
    {
        try
        {
            await DoAsyncStuff();
        }
        catch
        {
            Console.WriteLine("catch");
        }
        finally
        {
            Console.WriteLine("finally");
        }
    }

    private static async Task DoAsyncStuff()
    {
        await Task.Delay(1);
        throw new Exception();
    }
}


Neither catch nor finally is getting hit. I know that exceptions which are being raised in async void methods are being swallowed but didn't think that those in a try block would get swallowed aswell.

For reference:
https://stackoverflow.com/a/5383408
https://stackoverflow.com/a/16158374

^ Those answers state that the exceptions are getting catched
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

async void
C#CC# / help
5mo ago
✅ Async void method testing in xUnit
C#CC# / help
12mo ago
.Net framework async controllers
C#CC# / help
11mo ago
✅ async .NET MAUI binding
C#CC# / help
3y ago