I've studied that: With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException
thrown by String's charAt()
method.
what its mean?
according to that code there is no need to put try catch block in code, but i've seen compiler forces to put the code in try catch block.
I'm very confused what they are exactly?
A checked exception must be handled either by re-throwing or with a try catch block, a runtime isn't required to be handled. An unchecked exception is a programming error and are fatal, whereas a checked exception is an exception condition within your codes logic and can be recovered or retried from.
ClassNotFoundException, IOException, SQLException etc are the examples of the checked exceptions. I/O Exception: This Program throw I/O exception because of due FileNotFoundException is a checked exception in Java.
IOException
that is thrown when a file cannot be opened. These exceptions occur even if there is nothing wrong with the program. It is necessary, therefore, to tell the program how to handle the exception.NullPointerException
is thrown when a value is read on a null
object. Thus an Unchecked Exception represents a problem that requires a manual fix by the programmer. It is reasonable for the program to crash in order to avoid erroneous behavior, so a try-catch block is not required (but might be desirable in order to provide mitigation, such as displaying an error to the user). If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With