//user defined exception class MyException extends Exception{ String str1; MyException(String str2) { str1=str2; } public String toString(){ return ("MyException Occurred: "+str1) ; } } class EH1{ public static void main(String args[]) throws ArithmeticException,ArrayIndexOutOfBoundsException{ //throws try{ System.out.println("Starting of try block"); //throw throw new MyException("This is My error Message"); } catch(MyException exp){ System.out.println("Catch Block") ; System.out.println(exp) ; } //nested try catch try{ try{ try{ int arr[]= {1,2,3,4}; System.out.println(arr[10]); }catch(ArithmeticException e){ System.out.print("Arithmetic Exception"); System.out.println(" handled in try-block3"); } } catch(ArithmeticException e){ System.out.print("Arithmetic Exception"); System.out.println(" handled in try-block2"); } } //catch hierarchy catch(ArithmeticException e3){ System.out.print("Arithmetic Exception"); System.out.println(" handled in main try-block"); } catch(ArrayIndexOutOfBoundsException e4){ System.out.print("ArrayIndexOutOfBoundsException"); System.out.println(" handled in main try-block"); } catch(Exception e5){ System.out.print("Exception"); System.out.println(" handled in main try-block"); } //finally finally{ System.out.println("Finally block executed"); } } } /* OUTPUT: Starting of try block Catch Block MyException Occurred: This is My error Message ArrayIndexOutOfBoundsException handled in main try-block Finally block executed */