【发布时间】:2014-09-09 18:42:44
【问题描述】:
我正在使用Netbeans 8 IDE,但我遇到了这种奇怪的情况。假设我在 throws 和 Exception 的类中有一个方法,当我调用该方法时 Netbeans 不会强制执行 try catch。有时可能会出现Exception,但未捕获。
为什么 Netbeans 不强制执行 try catch 方法?
这是一个例子:
public class MyMethodClass {
public MyMethodClass() {}
public void someMethod() throws NullPointerException {
// do something
if(something == null) {
throw new NullPointerException();
}
// do something else
}
}
public class MyClass {
public MyClass() {
MyMethodClass mmc = new MyMethodClass();
// Here Netbeans does not force me to use a try catch, why?
mmc.someMethod();
}
}
【问题讨论】:
-
RuntimeExceptions 不需要处理。
标签: java exception netbeans exception-handling try-catch