Exception for missing data

后端 未结 7 915
难免孤独
难免孤独 2021-02-04 23:12

I was wondering what kind of exception should one throw for missing data. For example if an xml node doesn\'t contain data. It would be easy to \"throw new Exception(...

7条回答
  •  别跟我提以往
    2021-02-04 23:53

    throw new Exception("my message"); (or other built in Exception) is often the correct approach. The alternative is an explosion of Exception classes that may only get used once.

    If new Exceptions are warranted they should be created in the context of the domain, not the problem.

提交回复
热议问题