YouTip LogoYouTip

Exception Chain

# Java Example - Chained Exceptions [![Image 3: Java Examples](#) Java Examples](#) The following example demonstrates using multiple catch blocks to handle chained exceptions: ## Main.java File public class Main{public static void main(String args[])throws Exception{int n=20,result=0; try{result=n/0; System.out.println("Result is+result); }catch(ArithmeticException ex){System.out.println("Throw arithmetic exception: "+ex); try{throw new NumberFormatException(); }catch(NumberFormatException ex1){System.out.println("Manually throw chained exception : "+ex1); }}}} The output of the above code is: Throw arithmetic exception: java.lang.ArithmeticException: / by zero Manually throw chained exception : java.lang.NumberFormatException [![Image 4: Java Examples](#) Java Examples](#)
← Net UrldateNet Url β†’