【发布时间】:2021-07-27 13:06:11
【问题描述】:
这个堆栈跟踪被抛出:
System.Threading.Tasks.TaskCanceledException: The operation was canceled.
---> System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request.
我想准确地捕捉到这个异常,而不是一般的{Exception ex}
- 我添加了哪一个?
- 这里应该使用哪条规则?
- 最后一个 (
SocketException) 还是第一个 (TaskCanceledException) 应该被抓到?
谢谢!
【问题讨论】:
-
TaskCanceledException.