Packageexception; Public classTestException { Public Static voidMain (string[] args) { for(inti=0;i<4;i++) { Try { intK; Switch(i) { Case0: intzero= 0; K=911/Zero; Break; Case1: intb[]=NULL; K= B[0]; Break; Case2: intc[]=New int[2]; K=c[9]; Break; Case3: CharCh= "abc". CHARAT (99); Break; } } Catch(ArithmeticException e) {System.out.println ("Error 1" +e.getmessage ()); E.printstacktrace (); } Catch(NullPointerException e) {System.out.println ("Error 2" +e.getmessage ()); E.printstacktrace (); } Catch(arrayindexoutofboundsexception e) {System.out.println ("Error 3" +e.getmessage ()); E.printstacktrace (); } Catch(Exception e) {System.out.println ("Error 4" +e.getmessage ()); E.printstacktrace (); } } }}
Build the exception package, write the Testexception.java program, the main method has the following code, to determine the possible exceptions, to capture processing.