What is Exception Handling?
Exception Handling is a mechanism to handle runtime errors. It is mainly used to handle checked exceptions.
1.) What is the difference between Checked Exception and Unchecked Exception?
1)Checked Exception:
The classes that extend the Throwable class except RuntimeException and Error are known as checked exceptions e.g.IOException, SQLException, etc. Checked exceptions are checked at compile-time.
2)Unchecked Exception:
The classes that extend RuntimeException are known as unchecked exceptions e.g. ArithmeticException, NullPointerException, etc. Unchecked exceptions are not checked at compile-time.
2.) What is the base class for Error and Exception?
Throwable.
3) Is it necessary that each try block must be followed by a catch block?
It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.
4.) What is finally block?
finally block is a block that is always executed.
5.) Can finally block be used without catch?
Yes, by try block. finally must be followed by either try or catch.
No comments:
Post a Comment
Submit a Comment