鱼友7557
2023-02-26
#提问# 鱼皮大大,你好,冒昧叨扰了。这里有一个一直很困扰我的问题: 在《Introduction to Java Programming and Data Structures》第十二版中有这样一段: In most cases, unchecked exceptions reflect programming logic errors that are unrecoverable. For example, a NullPointerException is thrown if you access an object through a reference variable before an object is assigned to it; an `IndexOutOfBoundsException` is thrown if you access an element in an array outside the bounds of the array. These are logic errors that should be corrected in the program. Unchecked exceptions can occur anywhere in a program. To avoid cumbersome overuse of try-catch blocks, Java does not mandate that you write code to catch or declare unchecked exceptions.  请问您知道这里第一句最后的“unrecoverable”是指啥吗?我以前的理解是这个逻辑问题通过代码没办法修复,它是客观存在的,无法避免的。比如一个网站上提供注册用户的功能,名字有的用户填的符合校验逻辑,有的就会不符合,不符合时就可以抛出 unchecked exception。但是你无法去预测一个客户会填写啥,这个就相当于不可修复的逻辑漏洞。但是后来想想, FileNotFoundException,文件存在与否也可以说是代码没办法修复的呀,所以这里的logic errors that are unrecoverable 到底啥意思呢? 还有就是我在《https://wx.zsxq.com/mweb/views/weread/search.html?keyword=Spring揭秘》第三版368页时看到,作者在分析既往事务处理缺陷时有如下一段(见图片)。 这里写“事务处理过程中的异常应该不可恢复”,得出结论是应该用非检查型异常。我更晕乎了,这里的“事务不可恢复”又是啥意思?又是咋得出用非检查异常的结论?感觉跟上面有些同源,但是我不得其义。请问 鱼皮大大对这个有啥理解吗? 感谢!
0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
下载 APP