问题
What is the best method to distinguish between two exception of the same type but thrown for different reasons.
For example InvalidOperationException
can be thrown attempting to access an empty sequence, but it can also be thrown when using the Concurrent object (e.g. BlockingCollection
)
From my reading I've taken the conclusion that using the BlockingCollection.CompleteAdding()
to signal completion is perfectly fine and as such one would need to catch the Exception and handle appropriately (exit the task for instance)
What is the best way to filter these without having to use the message content?
Edit: They both appear to have the same HResult value.
来源:https://stackoverflow.com/questions/34281230/distinguish-between-exception-of-same-type