Exception handler in Java


Excepiton: In Java, an exception is an event that disrupts the normal flow of the program. It is an object which is thrown at runtime.

Exception hadnling: The Exception Handling in Java is one of the powerful mechanism to handle the runtime errors so that normal flow of the application can be maintained.

Exception Handling is a mechanism to handle runtime errors such as ClassNotFoundException, IOException, SQLException, RemoteException, etc.

Example for exception handling in Java:

public class JavaExceptionExample{
  public static void main(String args[])
   int a = 10;
      int z= a/0;

   catch(ArithmeticException e)

Types of Java Exceptions:

  1. Checked Exception
  2. Unchecked Exception
1. Checked Exception: The classes which directly inherit Throwable class except RuntimeException and Error are known as checked exceptions e.g. IOException.. 
Checked exceptions are checked at compile-time.

2. Unchecked Exception: The classes which inherit RuntimeException are known as unchecked exceptions e.g. ArithmeticException, ArrayIndexOutOfBoundsException etc. Unchecked exceptions are not checked at compile-time, but they are checked at runtime.

Java exception keywords:
  1. try
  2. catch
  3. fanally
  4. throw
  5. throws


Related topics

Please use contact page in this website if you find anything incorrect or you want to share more information about the topic discussed above.