我在测试代码中写了这段代码,但是抛出的One or more errors occurred. (A task was canceled.)
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()
{
BaseAddress = new Uri("https://www.taobao.com"),
Timeout = TimeSpan.FromMilliseconds(10)
};
Assert.Throws<TimeoutException>(() =>
{
var s = client.GetAsync("").Result;
});Assert.Throws() Failure
Expected: typeof(System.TimeoutException)
Actual: typeof(System.AggregateException): One or more errors occurred. (A task was canceled.)大家在代码中都是如何捕获这个错误的呢?
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/644/viewspace-3157253/ ,如需转载,请注明出处,否则将追究法律责任。