Java – unchecked exceptions will be better checked

I realize that in Java, the relative advantage between checking exceptions and unchecked exceptions is a be example discussion, and I'm not going to revisit the whole debate

Instead, I want to ask a very specific question, because I'm reading Joshua Bloch's second edition of effective Java As I was reading, I noticed that in project 59 ("avoid unnecessary use checking exceptions"), Joshua gave an example of using checking exceptions in the Java API Specifically, in the object:

protected Object clone()
            throws CloneNotSupportedException

... then think it should be an unchecked exception

Then I'll see if he has an opposite example, but I can't find one

So I want to ask if someone can give a sample API in Java that uses unchecked exceptions, but if a checked exception is a better choice, explain why A real-world example is preferable, but if it can also illustrate things, I can accept a creative example

Editor: for those who voted against this non constructive, I would like to make it clear that I am not looking for opinions, debates, arguments or expanding the discussion I didn't vote either Instead, I am looking for examples to draw a clear analysis of how benefits outweigh costs (implicitly, there are costs.) That is to say, I doubt whether the nature of the problem is possible I think if Jon skeet can't do this, then it's impossible So maybe you're right to close if you have to

Editor: Although I didn't respond, I will award Jon's honor

Solution

Yup,easy: Integer. ParseInt throws numberformatexception, which is unchecked

However, if you are parsing potentially incorrect data, you must consider catching exceptions - you may ignore the data, or you may report and continue It doesn't have the equivalent of Java Net Tryparse, which allows you to easily ignore bad data Basically, you need to know that you need to catch exceptions without provoking the compiler Gerl

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>