我有这样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和三个例外中的一个 –