0
//Assume list1 and list2 are populated with states as 2
foo (List<Class1> list1, List <Class1> list2) {
boolean error = false;
try {
operate on list1
} catch (Exception e) {
error = true;
//Modify list1 objects to state 1
}
try {
operate on list2
} catch (Exception e) {
error = true;
//Modify list2 objects to state 1
}
//What are the problems and what is the best practice for this
if (error)
throw new Exception(…); //How should i really rethrow the exception
}
設計是否合理?如果第一個操作已經出現錯誤,並且只打算拋出異常,那麼在list2上操作的意義何在?爲什麼不馬上扔? –