Will a java exception terminate the whole java application?

后端 未结 5 2039
闹比i
闹比i 2021-02-04 10:19

I used to think that when an exception happened, the whole java application will be terminated. For example, I write a test function to test my idea.

public void         


        
5条回答
  •  南方客
    南方客 (楼主)
    2021-02-04 10:43

    my question is ,in what condition ,a exception will cause the whole application to be terminated?

    It won't ever. Only System.exit() causes the whole program to terminate (and a JVM crash)

    Think of an Exception and like a powerful break; which can break out of methods. A break could result in a loop exiting and if the last loop in the only non daemon thread, the program will exit. But it doesn't cause it, even though it might be the last thing you see before you program dies.

提交回复
热议问题