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

前端 未结 10 2032
执念已碎
执念已碎 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:11

    It seems pretty obvious that nothing more will run after JVM quit, or will run code in that killed thread. Obvious. So, when the JVM is running, every code that will run, will run, and after a JVM quit or inside a dead thread , nothing will run, even any kind of code. So, there is no way to prevent, but if there is a need to the finally clause, put it.

提交回复
热议问题