Packageunit5;ImportJava.util.Scanner;ImportJavax.print.CancelablePrintJob;ImportJavax.sound.midi.SysexMessage;ImportUnit4.interfacedemo; Public classTrycatchdemo { Public Static voidMain (string[] args) {intA=0,b=0,c=0; Try{a=integer.parseint (args[0]); b=integer.parseint (args[1]); C=a/b; System.out.println ("C=" +c); System.out.println ("* * Normal Execution"); System.out.println ("Real division does not produce a mathematical class exception: 3.0/0.0" + (3.0/0.0)); } Catch(arrayindexoutofboundsexception E1) {System.out.println ("This program requires two parameters!"); }Catch(numberformatexception E2) {System.out.println ("There must be numbers."); }Catch(ArithmeticException e3) {System.out.println ("Divisor cannot be zero"); System.out.println ("Please re-enter parameters"); Scanner in=NewScanner (system.in); b=In.nextint (); C=a/b; System.out.println ("C=" +c); } }}
Try-catch Example