所以我之前经常这样处理
//重新抛出 RuntimeException
public class ThrowsDemo {
public void demo4throws() {
try {
new ThrowsSample().sample4throws();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
//打印日志
@Slf4j
public class ThrowsDemo {
public void demo4throws() {
try {
new ThrowsSample().sample4throws();
} catch (IOException e) {
log.error("sample4throws", e);
}
}
}
//继续往外抛,但是需要每个方法都添加 throws
public class ThrowsDemo {
public void demo4throws() throws IOException {
new ThrowsSample().sample4throws();
}
}但是我一直不明白
这个方法为什么不直接帮我做
反而要让我很多余的加上一步
我处理和它处理有什么区别吗?
而且变的好不美观
本来缩进就多,现在加个try-catch更是火上浇油
public class ThrowsDemo {
public void demo4throws() {
try {
if (xxx) {
try {
if (yyy) {