18-02-25 ---------- Q)What is the hierarchy of exception classes? =>java.lang.Throwable is the super class of all exception classes in Java. =>It has 2 sub classes. 1)java.lang.Exception 2.)java.lang.Error =>java.lang.Error class representing exceptions can't be handled by application developers.They are related to JVM issues. =>It means in Java application, we can handle those exceptions which are sub classes of only java.lang.Exception. =>java.lang.Exception class has many sub classes. These sub classes can be divided into two areas. 1)unchecked exception classes 2)checked exception classes =>java.lang.RuntimeException and its sub classes represent unchecked exceptions. =>Every other sub class of java.lang.Exception is of type checked. Q)How many "catch" blocks can be associated with one try block? =>Any many. =>It depends upon the number of different exceptions that may be raised in try block. =>Whenever we are writing multiple catch blocks for a try block, ensure that super class exception type should come last. Otherwise, Java compiler causes compilation errors as unreachable code is a syntactical error in Java. Q)Example program on multiple catch blocks for one try block. import java.util.Scanner; class MultiCatchExample{ public static void main(String[] args) { int quotient=1;//identity of division System.out.println("Program started"); Scanner scanner=new Scanner(System.in); try { System.out.print("Enter the numerator:"); int n=scanner.nextInt(); System.out.print("Enter the denominator:"); int d=scanner.nextInt(); quotient=n/d; System.out.println("Quotient is "+quotient); } catch (ArithmeticException e) { System.out.println(e.getMessage()); } catch(java.util.InputMismatchException e) { System.out.println("Please enter integral numbers only"); e.printStackTrace(); } catch(Exception e) { System.out.println("Something went wrong"); } System.out.println("Program ended successfully"); } } Q)What is an unchecked exception? =>For which type of exceptions, Java compiler doesn't force to implement exception handling, they are known as unchecked exceptions. Q)What is an checked exception? =>For which type of exceptions, Java compiler forces to implement exception handling, they are known as checked exceptions. =>For which type of exceptions, non-handling is a syntactical error reported by the compiler, those exceptions are known as checked exceptions.