Catchwho.java
Source:
public class Catchwho {
public static void Main (string[] args) {
try {
try {
throw new ArrayIndexOutOfBoundsException (); the problem to be addressed
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println ("arrayindexoutofboundsexception" + "/ inner layer try-catch");
}
throw new ArithmeticException ();
}
catch (ArithmeticException e) {
System.out.println (" occurring arithmeticexception");
}
catch (ArrayIndexOutOfBoundsException e) {System.out.println ("arrayindexoutofboundsexception" + "/ outer layer Try-catch ");
}
}
}
Prediction program Run Result: arrayindexoutofboundsexception/ outer Try-catch
occur ArithmeticException
arrayindexoutofboundsexception/ outer Try-catch
Actual running results:
Source:
public class CatchWho2 {
public static void Main (string[] args) {
try {
try {
throw new ArrayIndexOutOfBoundsException ();
}
catch (ArithmeticException e) {
System.out.println ("arrayindexoutofboundsexception" + "/ inner layer try-catch");
}
throw new ArithmeticException ();
}
catch (ArithmeticException e) {
System.out.println (" occurring arithmeticexception");
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println ("arrayindexoutofboundsexception" + "/ outer try-catch");
}
}
}
Prediction program Run Result:arrayindexoutofboundsexception/ inner layer try-catch
occur ArithmeticException
arrayindexoutofboundsexception/ outer Try-catch
Actual running results:
Multi-layered anomaly capture