public class extest {
public static void main(String[] argv) {
try {
- System.out.print("THROWS: ");
+ System.out.print("throw Exception: ");
sub();
System.out.println("failed.");
} catch (Exception e) {
}
try {
- System.out.print("NATIVE: ");
+ System.out.print("native Exception: ");
System.arraycopy(null, 1, null, 1, 1);
System.out.println("failed.");
} catch (Exception e) {
- System.out.println("passed");
+ System.out.println("passed.");
}
try {
- System.out.print("NULL: ");
+ System.out.print("NullPointerException: ");
int[] ia = null;
int i = ia.length;
System.out.println("failed.");
}
try {
- System.out.print("ARITHMETIC: ");
- int i = 1;
- int j = 0;
- int k = i / j;
+ System.out.print("ArithmeticException: ");
+ int i = 1, j = 0, k = i / j;
System.out.println("failed.");
} catch (ArithmeticException e) {
System.out.println("passed.");
}
- System.out.println("NULL (without catch): ");
+ try {
+ System.out.print("ArrayIndexOutOfBoundsException: ");
+ int[] ia = new int[1];
+ ia[1] = 1;
+ System.out.println("failed.");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ System.out.println("passed.");
+ }
+
+ try {
+ System.out.print("NegativeArraySizeException: ");
+ int[] ia = new int[-1];
+ System.out.println("failed.");
+ } catch (NegativeArraySizeException e) {
+ System.out.println("passed.");
+ }
+
+ try {
+ System.out.print("ClassCastException: ");
+ Object o = new Object();
+ Integer i = null;
+ i = (Integer) o;
+ System.out.println("failed.");
+ } catch (ClassCastException e) {
+ System.out.println("passed.");
+ }
+
+ System.out.println("NullPointerException (without catch): ");
String s = null;
int i = s.length();
System.out.println("failed.");
-THROWS: passed.
-NATIVE: passed
-NULL: passed.
-ARITHMETIC: passed.
-NULL (without catch):
-Exception in thread "main" java/lang/NullPointerException
+throw Exception: passed.
+native Exception: passed.
+NullPointerException: passed.
+ArithmeticException: passed.
+ArrayIndexOutOfBoundsException: passed.
+NegativeArraySizeException: passed.
+ClassCastException: passed.
+NullPointerException (without catch):
+Exception in thread "main" java.lang.NullPointerException