容错能力的考虑

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......

  }

}

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

原文地址:https://www.cnblogs.com/donggongdechen/p/14969994.html