我在 Eclipse 中使用以下代码:
public class Foo {
public static final Bar bar = new Bar(20);
}
public class Bar {
public int value;
// This needs to be able to be called in places other than
// just Foo, and there it will need to throw.
public Bar(int value) throws Exception {
if(value == 0) {
throw Exception("Error. Value cannot be 0 when constructing Bar.");
}
return;
}
}
这在 Foo(第 2 行)中给了我一条错误消息,上面写着“未处理的异常类型异常”,即使在实践中,此代码永远不会发生此异常。我可以在 Eclipse 中禁用此错误,以免打扰我,还是有其他方法可以处理此错误?
提前感谢您的答案!