What are unchecked exceptions and how we can invoke the method that declares checked exceptions?
There are two categories of exception
1. Checked
2. Unchecked
Unchecked Exception:
Unchecked exceptions are RuntimeException and all its
descendent classes. We have often met with this exception
ArrayIndexOutOfBounds or NullPointerException such type of
exceptions are an example of Unchecked Exception. Unchecked
Exception is not connected to outer resources(files e.g text file).
Compiler will not check your application whether you are handling
or not.
Checked Exception:
In Checked Exception application is connected to outer resources.
Checked Exceptions are checked by compiler. It's compulsory to
handle if you do not handle them compiler will never generate the
class. Compiler has to involve becuase you are using outside
resources.
Methods like File Handling or Databases these are outside resources
and they use checked exception. When using classes that involves or
opens a particular file lets you EXPLICITLY invoke throws those
Exceptions or use try and catch block. Because when you
compile(checked exception), Java checks to see if the file exists
at the specified path.
We can use FileInputStream for example which is used to specify
file path and it throws a checked Exception FileNotFoundException
and when we are reading a file then it throws IOException and when
we are about to close a input stream file it also throws the same
Exception as the read method does IOException.
This was an example of a method from which we can invoke checked exception
IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP
What are unchecked exceptions and how we can invoke the method that declares checked exceptions?