Checked exceptions complicate this scenario a bit, because they force you to add catch clauses in places where you may not be ready to handle an error. This results in the "harmful if swallowed" problem: try { // ... to do something useful } catch(ObligatoryException e) {} // Gulp! Programmers (myself included, in the 1st edition of this book) would just do the simplest thing, and "swallow" the exception—often unintentionally, but once you do it, the compiler has been satisfied, so unless you remember to revisit and correct the code, the exception will be lost. The exception happens, but it vanishes completely when swallowed. Because the compiler forces you to write code right away to handle the exception, this seems like the easiest solution even though it’s probably the worst thing you can do. 中文的太长了 打起来有点慢 而且不是原版 看看E文怎么写的吧
clauses in places where you may not be ready to handle an error. This results in the "harmful
if swallowed" problem:
try {
// ... to do something useful
} catch(ObligatoryException e) {} // Gulp!
Programmers (myself included, in the 1st edition of this book) would just do the simplest
thing, and "swallow" the exception—often unintentionally, but once you do it, the compiler
has been satisfied, so unless you remember to revisit and correct the code, the exception will
be lost. The exception happens, but it vanishes completely when swallowed. Because the
compiler forces you to write code right away to handle the exception, this seems like the
easiest solution even though it’s probably the worst thing you can do. 中文的太长了 打起来有点慢 而且不是原版 看看E文怎么写的吧
为什么被检查的异常强制你在可能没有准备好的情况下处理错误的时候被迫加上catch子句 用Throws不就行了?
我是 .NET 的 有快1年工作经验了 就是觉得Java的书写得都比较好 所以看着Java的书学C# 以后也想跳到Java领域
请注意我说的“没有被catch获者throws,会通不过编译”,其中已经包括了throws这种情况,就是说你必须“处理”,其实错误往外面抛也是一种“处理”,就好像地方处理不了的问题会上报中央一样,而“非检查异常”你可能根本就不知道方法会发生什么异常,就好像地方的维*稳一样,外面看起来风平浪静,所有的错误貌似内部消化,但也有被“捅出来”的时候。