Distinguish between exception of same type

感情迁移 提交于 2019-12-23 10:07:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!