Will a java exception terminate the whole java application?

后端 未结 5 2128
闹比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:35

    There are two main types of exceptions:

    • Not runtime exceptions

    It indicates the system is working properly. You must catch the exception or it won't compile. It will never terminate the application. If you want to terminate anyway, you have to call System.exit(ERROR_NUMBER) in the catch block or throw a runtime exception.

    • Runtime exceptions

    Indicates a system error (eg. application server misconfiguration). You don't have to catch it. If you don't catch it, it terminates the application or if you write a J2EE application the AS might handle it and continue your app.

提交回复
热议问题