Create custom exception or use built-in exceptions?

后端 未结 5 1894
执念已碎
执念已碎 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 04:59

    If the BCL contains classes that already convey the meaning you want (ArgumentNullException, for instance), use those.

    Reserve using your own exception classes for things that are specific to your API.

    If you feel that you can add information, by all means raise your own exception but do not swallow exceptions - propagate them up as inner exceptions of your own.

提交回复
热议问题