Suppose I have the following method, and the code that calls it:
public async Task<MyResult> PerformAction(string parameter)
{
if(parameter == "fail")
throw new Exception("You wanted me to fail.");
return await MyResult.Create(parameter);
}
var resultOne = await PerformAction("fail");
var resultTwo = await PerformAction("success");
This would work fine - but it would throw an exception, incurring the performance cost of the exception.
Is there a way to indicate to the caller that a task failed, without throwing an exception?