Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V3231. Async method returning 'void'...
menu mobile close menu
Additional information
toggle menu Contents

V3231. Async method returning 'void' throws an exception. Callers will not be able to catch this exception. Consider replacing the return type with 'Task'.

Feb 06 2026

The analyzer detected a method with the async modifier and the void return type. An exception is thrown inside this method. Exceptions within such methods cannot be caught or handled by the calling code because the method does not return the Task object, which is used to await the completion of the asynchronous operation and to handle exceptions.

According to guidelines, these methods should not be used outside event handlers. This is because they cannot be used with await, their completion cannot be controlled and exceptions thrown within them cannot be handled in the calling context. As a result, unhandled exceptions may lead to process crash.

The example:

async void LoadDataAsync(string data)
{
  await Task.Delay(100);

  if (data == null)
    throw new InvalidOperationException("Data loading error.");

  ....
}

void Start(string data)
{
  try
  {
    LoadDataAsync(data);
  }
  catch
  {
    ....
  }
}

The exception thrown in the LoadDataAsync method will not be caught in the Start method, as LoadDataAsync is the async method with the void return type.

The fixed example:

async Task LoadDataAsync(string data)
{
  await Task.Delay(100);

  if (data == null)
    throw new InvalidOperationException("Data loading error.");
    
  ....
}

async Task Start(string data)
{
  try
  {
    await LoadDataAsync(data);
  }
  catch
  {
    ....
  }
}

Now the asynchronous operation is represented by the Task object. This allows the calling context to await its completion and handle the exception.

This diagnostic is classified as: