我知道未经检查的异常(RuntimeExceptions)通常会导致您的事务回滚,但是如果您在同一方法中捕获该异常,会发生什么? 当errorOccurred
是true
时,我想回滚整个事务。但我想知道捕获异常是否会吞噬RuntimeException,从而导致事务无法回滚? 这份代码是否仍然回滚事务?
public static void main(String[] args) {
try {
// boring stuff...
if(errorOccurred)
throw new RuntimeException("RuntimeException is thrown.");
} catch (Exception e) {
System.out.println("RuntimeException cought. Does is still rollback transaction?");
}
}