Skip to content

Latest commit

 

History

History
18 lines (12 loc) · 877 Bytes

PH_S032.md

File metadata and controls

18 lines (12 loc) · 877 Bytes

PH_S032 - Throws in Potentially Async Method

Problem

A method denotes itself as asynchronous by returning a Task and using the Async suffix. However, it does not use the async and await keywords but returns the tasks explicitly. If such a potentially async method throws an exception inside its body, it behaves differently to methods using the async principles. The latter encapsulates the thrown exceptions inside the return task object. The former throws the exception upon invocation.

Solution

Encapsulate the exceptions in a task using Task.FromException(...).

Options

# A white-space separated list of exception types to not report. The sub-types of these types will be excluded too.
# Format: <type-specifier1> <type-specifier2> ...
dotnet_diagnostic.PH_S032.exclusions = System.ArgumentException System.NotImplementedException