我有這樣finally塊來表現不同
String str = null;
try{
...
str = "condition2";
}catch (ApplicationException ae) {
str = "condition3";
}catch (IllegalStateException ise) {
str = "condition3";
}catch (Exception e) {
str = "condition3";
}
if(str == null){
str = "none";
}
現在我想在一行來總結所有str = "condition3";
的條件。終於塊運行永遠不會滿足我的需求。還有什麼可以做的。
你這是什麼意思關鍵字「總結」? –
我不確定你在尋找什麼好處...如果你想讓錯誤字符串對所有3個例外都是相同的,那麼使用下面的答案。如果沒有,並且在我們沒有看到的每個異常塊中都有更多的代碼,那麼我不會看到重複一行很糟糕。 – billjamesdev
這是什麼意思「all str =」condition3「?如果你想總結所有str,它將包含cond2和三個例外中的一個 –