In Java, is the “finally” block guaranteed to be called (in the main method)?

前端 未结 10 2043
执念已碎
执念已碎 2020-12-06 09:17

I\'m a Java rookie and I was wondering, if I have the following typical Java code

public class MyApp {
  public static void main(String[] args) {
    try {
          


        
10条回答
  •  情书的邮戳
    2020-12-06 10:12

    Basically yes, except for the note listed here (emphasis mine):

    If the JVM exits while the try or catch code is being executed, then the finally block may not execute. Likewise, if the thread executing the try or catch code is interrupted or killed, the finally block may not execute even though the application as a whole continues.

提交回复
热议问题