容错能力的考虑

void f(vector<string>& v, int i, const char *p) {

  if(p == nullptr)

    return;

  if(i<0 || v.size()<=i)

    error("bad index.");

  string s = v[i];

  if(s == p) {

    //process......

  }

}

写代码对程序容错能力要做考虑,对异常的情况也要编写对应的处理逻辑,而不是仅仅按正常情况去写。

posted @ 2021-07-04 21:31  东宫得臣  阅读(66)  评论(0编辑  收藏  举报