基于Oracle的定义,Checked异常和Runtime异常之间的不同点之一是“可恢复的功能”。但是,我不明白如何区分可恢复异常和不可恢复异常之间的区别。有人告诉我:
但我不明白其中的区别。所以,我给出了如下几个场景:
磁盘上不存在读取文件X
=> This situation is recoverable or un-recoverable? Why?
=> In this situation, if user choose the another file (through UI), it is the recoverable exception?
将数字除以0 (例如:1/0)
=> This situation is recoverable or un-recoverable? Why?
=> In this situation, if user choose the another number <> 0 (through UI), it is the recoverable exception?
数组X的长度为N,调用X [-1]或X [N + 1]是不可能的
=> This situation is recoverable or un-recoverable? Why?
=> In this situation, if user choose the another index (through UI), it is the recoverable exception?
对象X = null,裁判员为X(例如,函数Y调用X,......)
=> This situation is recoverable or un-recoverable? Why?
=> In this situation, if user choose the another object not null (through UI), it is the recoverable exception?
字符串X至少包含非数字字符,将X转换为数字
=> This situation is recoverable or un-recoverable? Why?
=> In this situation, if user choose the another string (through UI), it is the recoverable exception?
我不知道为什么这个异常是运行时异常,因为我认为当发生此异常时,用户只需更改另一个字符串(可能是通过UI)继续程序而无需重新编写代码,例如:< / p>
字符串X =“ba1” - &gt;整数Y(不可能)
更改X =“123” - &gt;整数Y(可能),此操作不需要修复代码(???)
示例:
主要是第五种情况,我不知道为什么它是运行时异常而程序员无法对源代码做任何事情(重写代码)&lt;&lt;&lt;&lt;