I played with asynchronous calls in .NET 4.6.1, and I wonder what the correct way to throw errors is to implement an interface interface that expects an asynchronous method, but actually synchronous. For instance:
public interface ISomeInterface
{
Task ExecuteAsync();
}
public class SomeClass : ISomeInterface
{
public Task ExecuteAsync()
{
return Task.FromException(new Exception());
}
}
I found Task.FromException here .
So this .NET 4.6 still seems to advise wrapping exceptions. However, I could just write the following code:
public class SomeClass : ISomeInterface
{
public Task ExecuteAsync()
{
throw new Exception();
}
}
, try/catch, Exception, , , , Task.FromException , , , ( ). , , , , . - async, -, ?
, async . , ?