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.
package javaapplication1; public class JavaApplication1 { public static void main(String[] args) { int a[]; a = new int[10]; try { System.out.print(10/0); a[11] = 0; } catch(Exception e) { System.out.print(e.toMessage()); } } }
package javaapplication1; public class JavaApplication1 { public static void main(String[] args) { public static void main(String[] args) { // TODO code application logic here int a[]; a = new int[10]; try { a[9] = 0; try { int i,j; i=10; j=2; int k = i/j; } catch(Exception e1) { System.out.print("\nDivision By 0 is not possible"); } } catch(Exception e2) { System.out.print("\nArray index is out of range"); } finally { System.out.print("\nOk Then Bye"); } } } }