An exception is any unwanted thing which may interrupt the control flow of the program.

Exception hierarchy

Types of Exceptions

There are mainly 2 types of Exceptions – checked or unchecked.

  1. Checked Exception:

    Exceptions that are checked at compile time. If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using throws keyword.

  2. UnChecked Exception:

    exceptions that are not checked at the compiled time.

In Java exceptions under Error and RuntimeException classes are unchecked exceptions, everything else under throwable is checked.

How to Handle Exception

They are handled by 5 keywords.

  1. try
  2. catch
  3. throw
  4. throws
  5. finally

Throws Keyword:

Throws Keyword and finally keyword


Please enter your comment!
Please enter your name here