can't java unchecked exceptions be handled using try/catch block?

后端 未结 8 1950
旧时难觅i
旧时难觅i 2020-12-24 02:29

In a tutorial I found that Unchecked Exception can\'t be handled by your code i.e. we can\'t use try/catch block and the examples are exception

8条回答
  •  被撕碎了的回忆
    2020-12-24 03:05

    Yes you can handle the unchecked exception but not compulsory. Actually it depends on application developer. Below is the possible reason where i think required to handle even unchecked exception.

    • If your application is large where many developers are calling each other API. It is better to handle the unchecked exception otherwise at the end your program will crash which stop the other functionality. So even the simple NullPointerException can stop your program working.

    • Imagine you have one scheduler which processing the user data and which is in million size and for the bad data you only want to print the log not to stop working for other good data. In that case if you have not handle the exception one bad data can stop your program

提交回复
热议问题