Create custom exception or use built-in exceptions?

后端 未结 5 1891
执念已碎
执念已碎 2020-12-10 04:19

Currently I\'m in the process of writing a client class that utilizes DNS, Sockets, and SSL among other classes that love to throw exceptions. Other people will be implemen

5条回答
  •  执念已碎
    2020-12-10 05:09

    It is fine to throw your own exceptions if they add information, but don't swallow the exceptions from the underlying services unless there is a security concern.

    If you are catching one exception and and throwing a new one, assign the old one to the InnerException property of the new one. You can nest as many Exceptions as necessary in this way, which creates a hierarchical "view" into how the exception propagated, which is very helpful for debugging.

提交回复
热议问题