Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Why is the two exception types in Java named "checked" and "unchecked"? What is the reason behind those names?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
214 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you call a method which is declared to throw a checked exception (such as IOException), the compiler will check that you're either catching it or declaring that you rethrow it. Likewise, in order to throw such a checked exception in the first place, the compiler checks that you've declared it as part of the method signature.

Basically, it's a little bit like type checking, except in terms of which exceptions can be thrown by a method.

The compiler doesn't perform any checking for unchecked exceptions - so they can be thrown by any method, without the method declaring them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...