英文:
Does SneakyThrows actually stop an exception from propagating?
问题
我有这段代码:
@SneakyThrows
public void startDatabase() throws NotBoundException, RemoteException {
entityRepository = new EntityRepositoryImpl(DatabaseManagerImpl.getInstance());
registrar = new RegistrarImpl(entityRepository);
String process = ManagementFactory.getRuntimeMXBean().getName();
registrar.register();
LOG.debug("Started database with process id: " + process);
}
其中它抛出了异常 NotBoundException, RemoteException
,添加 @SneakyThrows
注解后,IDE 报告说这两个异常不再由该方法抛出。
Lombok 的 SneakyThrows 实际上会阻止异常传播吗?
英文:
I have this code:
@SneakyThrows
public void startDatabase() throws NotBoundException, RemoteException {
entityRepository = new EntityRepositoryImpl(DatabaseManagerImpl.getInstance());
registrar = new RegistrarImpl(entityRepository);
String process = ManagementFactory.getRuntimeMXBean().getName();
registrar.register();
LOG.debug("Started database with process id: " + process);
}
In which it throws an exception NotBoundException, RemoteException
adding the @SneakyThrows
annotation makes the IDE report that both these two exceptions are not thrown by the method (anymore).
Does Lombok SneakyThrows actually stop an exception from propagating?
答案1
得分: 1
不,它不能阻止异常继续传播。
> @SneakyThrows可以用于在不在方法的throws子句中实际声明的情况下,偷偷抛出已检查异常。
参考链接:https://projectlombok.org/features/SneakyThrows
英文:
No, it does not prevent the exception from propagating.
> @SneakyThrows can be used to sneakily throw checked exceptions without actually declaring this in your method's throws clause.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论