编程语言
首页 > 编程语言> > [Effective Java] Item 59 Avoid unnecessary use of checked exceptions

[Effective Java] Item 59 Avoid unnecessary use of checked exceptions

作者:互联网

Checked exceptions是要在合理使用API时无法避免异常,并且使用者也能采取有用的措施的情况下使用的。

如果不满足这两个条件,而且使用者其实也没有什么更好的办法去处理的话,unchecked exception可能会更适合。

我们来看CloneNotSupportedException,这个异常其实是因为,clone方法invoke了一个没有implement Cloneable这个Interface的object上而抛出的异常,这里其实有没有什么特别能处理的方法,然而API当时设计成了Checked exception是没有任何好处的。

标签:use,Checked,Effective,exception,API,使用者,exceptions,Java,异常
来源: https://blog.csdn.net/jzhong720/article/details/115035462