Exception for missing data

后端 未结 7 948
难免孤独
难免孤独 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:43

    For a general missing data scenario, where the data is referenced by a unique ID, then the KeyNotFoundException might be appropriate - e.g.

    throw new KeyNotFoundException($"Expected record for key {key} not found.");

    It is in the System.Collections.Generic namespace.

提交回复
热议问题