What factors should be taken into consideration when writing a custom exception class?

后端 未结 7 926
甜味超标
甜味超标 2020-12-29 15:38

When are custom Exception classes most-valuable?
Are there cases when they should or should not be used? What are the benefits?

Related

7条回答
  •  無奈伤痛
    2020-12-29 16:29

    My main reason for using custom exceptions would be encapsulation with multiple providers: having a SqlException leak out of a SqlDataAccess layer, and a SocketException out of a NetworkDataAccess layer makes calling code dependent on the particulars of your implementation. Better to wrap them into a DataAccessException or something.

提交回复
热议问题