Eclipse 编译以下代码没有任何问题,而当mvn
尝试编译此代码,结果编译失败:
try {
// Distribution.rep().get(id) returns a java.util.Optional
Distribution updated = Distribution.rep().transact(() -> {
Distribution distro = Distribution.rep().get(id).orElseThrow(() -> {
throw new NotFoundException("Couldn't find Distribution with ID '%s'.", id);
});
// Other stuff...
});
rs.setData(updated);
} catch (ExecutionException e) {
// Handle the error
} catch (Exception e) {
// Handle the exception
}
抛出的错误maven-compiler-plugin:3.1
is:
unreported exception java.lang.Throwable; must be caught or declared to be thrown
NotFoundException extends RuntimeException
. The transact
方法将所有运行时(?)异常包装在一个ExecutionException
在扔掉它们之前。不管怎样,这NotFoundException
(抛出时)应该被catch
条款为ExecutionException
, 所以有什么问题?
据我所知maven-compiler-plugin
似乎认为NotFoundException
is a Throwable
. NotFoundException
在我的代码(项目)中定义,所以maven-compiler-plugin
应该知道这件事...
编译器插件的源和目标定义为1.8
。有Java版本1.8.0_181
。尝试过maven-compiler-plugin
版本3.8.0
,得到相同的结果。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)