Exception for missing data

后端 未结 7 917
难免孤独
难免孤独 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-05 00:01

    Do not call "throw new Exception", because you don't know how to handle the exception.

    Define your own exception. Be more specific, such as XMLDataMissingException. Then you can give a meamingful message to user or log it.

提交回复
热议问题