Uncaught RuntimeException and finally clause: which comes first?

前端 未结 5 700
终归单人心
终归单人心 2021-01-11 10:28

A RuntimeException is thrown in try block without being caught, while the finally clause invokes System.exit().



        
5条回答
  •  忘掉有多难
    2021-01-11 11:01

    The thing is, when there is an exception thrown.. The JVM 1st execute code with inside finally block and then throw the exception if catched or it will throw the exception and terminate the thread. so here when System.exit(0) is present in the finally block it terminate the thread immediately so the JVM doesnt get chance to throw the exception. so the out put is just the "finally "

提交回复
热议问题