异常,不要求在程序处理这些异常。所以如果愿意,我们可以编写代码处理(使用 try…catch…finally )
这样的异常,也可以不处理。对于这些异常,我们应该修正代码,。如除 0 错误 ArithmeticException ,
错误的强制类型转换错误 ClassCastException ,数组索引越界 ArrayIndexOutOfBoundsException ,
使用了空对象 NullPointerException 等等
2、检查异常
检查异常则是除了 Error 和 RuntimeException 的其它异常。javac强制要求程序员为这样的异常做预备
处理工作(使用 try…catch…finally 或者 throws )。在方法中要么用try-catch语句捕获它并处理,要么用 throws 子句
声明抛出它,否则编译不会通过。如 SQLException , IOException , ClassNotFoundException 等。
[
创作打卡挑战赛
赢取流量/现金/CSDN周边激励大奖
](https://mp.csdn.net/activity/newclock?utm_campaign=marketingcard&utm_source=u013297881&utm_content=107162203)
rce=u013297881&utm_content=107162203)