+ 3

About Exceptions in java

Why it is categorized as checked and unchecked in java exceptions and why compiler is least bother about unchecked??

28th Sep 2022, 6:22 PM
Shreepriya HA
3 Answers
+ 4
For checked exceptions , there must be a mechanism by the developer to handled it if exception occurs. Because you can expect this may happen before hand. So you should ready with solution. For example: FileReader( file) or FileInputStream( file) , for file value, user may give wrong or invalid file name so it must be handled the case without terminating program.. Unchecked exception are those you can't handle those. So compiler checking for these is no use. Ex: Memory is full then it raise memory error. You can't do anything. Network or connection Error is another examples. You cannot do anything to handled those. So depends upon possibilities of handling those are categorized to checked and unchecked exceptions... Hope it helps..
28th Sep 2022, 7:43 PM
Jayakrishna šŸ‡®šŸ‡³
+ 4
if (api) method can throw an Exception but author of method want to force user-programmer to handle this exception his own way, can declare void method() throws SomeException { } and this exception has to be checked then. Java api has also some checked exceptions. other posible exceptions are unchecked
28th Sep 2022, 7:46 PM
zemiak
+ 1
It helped me a lot thank you
29th Sep 2022, 3:24 AM
Shreepriya HA