问题描述
我有一个类似于以下的设置。在AClass中,第throws e
行的Java编译器抱怨-
Unhandled exception: <path-to>.DatastoreException
(来自jdoodle的可编辑共享-jdoodle.com/a/2xbl)
那是为什么?我不是只在异常是IllegalArgumentException时抛出吗?
import java.lang.IllegalArgumentException;
import <path-to>.DependencyException;
import <path-to>.DatastoreException;
public class AClass {
public void someMethod() {
try {
new BClass().thisThrowsDatastoreException();
} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
throw e; //Javac complains in this line
} else if (e instance of DatastoreException) {
throw new DependencyException(e);
}
}
}
}
public class BClass {
public BClass() {}
public void thisThrowsDatastoreException() throws DatastoreException {
throw new DatastoreException();
}
}
public class DatastoreException extends Exception {
private static final long serialVersionUID = -2L;
public DatastoreException() {
super();
}
}
public class DependencyException extends RuntimeException {
private static final long serialVersionUID = -1L;
public DependencyException() {
super();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)