Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Exception handler in Java

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;
   try
   {
      int z= a/0;
   }
 
   catch(ArithmeticException e)
   {
       System.out.println(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

References:

  1. Sebesta,”Concept of programming Language”, Pearson Edu
  2. Louden, “Programming Languages: Principles & Practices” , Cengage Learning
  3. Tucker, “Programming Languages: Principles and paradigms “, Tata McGraw –Hill.
  4. E Horowitz, “Programming Languages”, 2nd Edition, Addison Wesley

Leave a Comment