本文介绍了在java中尝试catch-finally的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,如果我们在
中插入一个try-catch-finally的try块,那么finally块是否会被执行?

In Java, will the finally block not get executed if we insert a return statement insidethe try block of a try-catch-finally ?

推荐答案

当你打电话给 exit() finally 块将不会被执行$ c>在到达之前。 exit()调用将关闭JVM,因此不会运行任何后续代码行。

The only time a finally block will not be executed is when you call exit() before finally is reached. The exit() call will shutdown the JVM, so no subsequent line of code will be run.

编辑:这不完全正确。有关其他信息,请参阅以下评论。

This is not entirely correct. See the comments below for additional information.

这篇关于在java中尝试catch-finally的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 19:26