Core java interview questions on Exception Handling



1.What is Exception handling?
Testing the code and avoiding it from exception.

2.Difference between checked and unchecked exception?
Checked exception:The classes that extends throwable calss except RuntimeException and Error are known as checked exceptions. Example: IoException,SQL Exception etc...Checked Exceptions are at compile time.
Unchecked Exception:The classes that extend RuntimeException are known as Unchecked Exceptions.
Example:Arithmetic Exception null pointerException,ArrayIndexOutOf Bounds exception etc....Rather they are checked at runtime.

3.What is base class for error and exception?
Throwable is base class.

4.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.

5.What is finally block?
Finally block is to avoid resource leakage.and run always after try block

6.Can finally block be used without catch?
finally should have atleast a try block, catch is optional. The point of finally blocks is to make sure stuff gets cleaned up whether an exception is thrown or not.
finally should always be preceded by a try block.



Related Post

Comments


©candidjava.com