elibraryportal Logo

Exception Handling in Java

→ Handled the exception using try-catch' block where try block contains the code which is under observation for exceptions. annd catch block contains the remedy for the exception.If any error or exception occurs in the try block then the control jumps to catch block.

→ Exception Handling is mechanism to Handle runtime error.

→ Exception is an object or event that is thrown at runtime

→ An exception can occur due to many different reasons, some of them are:

  • A user has entered invalid data.
  • A file that needs to be opened cannot be found.
  • A network connection has been lost in the middle of communications or the JVM has run out of memory.

Normal Error

  • Syntax Error
  • Logical Error
  • Runtime Error

Advantage of Exception Handling

→ Advantage of Exception Handling to maintain the flow of the application is the given in scenario.

Hierarchy of Java Exception classes

Exception Handling

Exception Handling Keywords in Java

  • try
  • catch
  • finally
  • throw
  • throws