Create custom exception or use built-in exceptions?

后端 未结 5 1890
执念已碎
执念已碎 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:18

    It really depends on your audience, i.e. the consumers of your class.

    For example, if you are essentially wrapping a lot of different exceptions, it may be a good idea to create custom exceptions that would simplify the error handling in the consumer.

    If you do create custom exceptions, be sure to include the original exception into the InnerException of your custom exception, unless you explicitly have a reason to hide it. This will people using your class the most information available, as well as cover you if an exception comes back that your class doesn't completely cover.

提交回复
热议问题