xml 파일을 구문 분석하는 데 tinyxml을 사용하고 있으며 여기에서 오류 처리가 화살표 코드에 적합하다는 것을 알았습니다. 우리의 오류 처리는 단순히 메시지를 파일에보고하는 것입니다. 여기 xml 파싱에 대한 오류 처리
은 예입니다const TiXmlElement *objectType = dataRoot->FirstChildElement("game_object");
if (objectType) {
do {
const char *path = objectType->Attribute("path");
if (path) {
const TiXmlElement *instance = objectType->FirstChildElement("instance");
if (instance) {
do {
int x, y = 0;
instance->QueryIntAttribute("x", &x);
instance->QueryIntAttribute("y", &y);
if (x >= 0 && y >= 0) {
AddGameObject(new GameObject(path, x, y));
} else {
LogErr("Tile location negative for GameObject in state file.");
return false;
}
} while (instance = instance->NextSiblingElement("instance"));
} else {
LogErr("No instances specified for GameObject in state file.");
return false;
}
} else {
LogErr("No path specified for GameObject in state file.");
return false;
}
} while (objectType = objectType->NextSiblingElement("game_object"));
} else {
LogErr("No game_object specified in <game_objects>. Thus, not necessary.");
return false;
}
return true;
내가 화나게하고 그 위에 피고 아니지만, 사람이 작업을 수행 할 수있는 청소기 방법을 생각할 수 있다면 감사하겠습니다.
P. 예외는 옵션이 아닙니다.
편집 :
이렇게하는 것이 좋을까요?
이렇게하면 화살표 코드가 제거되지만 화살표 코드 종류는 모든 오류 로깅을 한 곳에서 처리합니다.