简体   繁体   中英

Why Class CloneNotSupportedException is a checked Exception and does not extend RuntimeException instead?

How can the caller of clone() possibly recover if they encounter a CloneNotSupportedException ? Why is it a checked Exception ?

Why is it a checked Exception?

I suspect the answer is really: "because when Java first came out, there was very little experience of when it would make sense for an exception to be checked." Back then, they didn't have Effective Java :)

There are various things like this - exceptions which are checked but probably shouldn't be, and occasions where the exception is unchecked but should be checked... Integer.parseInt throwing NumberFormatException probably being the clearest example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM