2 public static void main(String[] argv) {
3 System.out.println("---------- normal exceptions --------------------");
6 System.out.print("throw Exception: ");
8 System.out.println("FAILED");
9 } catch (Exception e) {
10 System.out.println("PASSED");
14 System.out.print("native NullPointerException: ");
15 System.arraycopy(null, 1, null, 1, 1);
16 System.out.println("FAILED");
17 } catch (Exception e) {
18 System.out.println("PASSED");
22 System.out.print("NullPointerException: ");
25 System.out.println("FAILED");
26 } catch (NullPointerException e) {
27 System.out.println("PASSED");
31 System.out.print("ArithmeticException: ");
32 int i = 1, j = 0, k = i / j;
33 System.out.println("FAILED");
34 } catch (ArithmeticException e) {
35 System.out.println("PASSED");
39 System.out.println("---------- test soft inline exceptions ----------");
42 System.out.print("ArrayIndexOutOfBoundsException: ");
43 int[] ia = new int[1];
45 System.out.println("FAILED");
46 } catch (ArrayIndexOutOfBoundsException e) {
47 String msg = e.getMessage();
49 if (msg != null && msg.compareTo("Array index out of range: -889275714") != 0) {
50 System.out.println("FAILED: wrong index");
53 System.out.println("PASSED");
58 System.out.print("NegativeArraySizeException: ");
59 int[] ia = new int[-1];
60 System.out.println("FAILED");
61 } catch (NegativeArraySizeException e) {
62 System.out.println("PASSED");
66 System.out.print("ClassCastException: ");
67 Object o = new Object();
70 System.out.println("FAILED");
71 } catch (ClassCastException e) {
72 System.out.println("PASSED");
76 System.out.print("OutOfMemoryError: ");
77 /* 100 MB should be enough */
78 byte[] ba = new byte[100 * 1024 * 1024];
79 System.out.println("FAILED");
80 } catch (OutOfMemoryError e) {
81 System.out.println("PASSED");
85 System.out.println("---------- no passed beyond this point ----------");
87 System.out.println("NullPointerException (without catch): ");
90 System.out.println("FAILED");
93 public synchronized static void sub() throws Exception {
97 public static void sub2() throws Exception {
101 public synchronized static void sub3() throws Exception {
105 public static void sub4() throws Exception {
106 throw new Exception();