3 public static boolean printStackTrace;
5 public static void main(String[] argv) {
8 if (argv[0].equals("stacktrace")) printStackTrace=true;
10 boolean catched = false;
12 pln("---------- normal exceptions --------------------");
15 p("throw new Exception():");
16 throw new Exception();
17 } catch (Exception e) {
24 /* check if catch block was executed */
30 p("throw new Exception() (from subroutines):");
33 } catch (Exception e) {
39 p("NullPointerException:");
43 } catch (NullPointerException e) {
51 pln("---------- test soft inline exceptions ----------");
52 pln("/* thrown twice to check the inline jump code */");
55 p("ArrayIndexOutOfBoundsException:");
56 int[] ia = new int[1];
59 } catch (ArrayIndexOutOfBoundsException e) {
60 String msg = e.getMessage();
62 if (msg == null || !msg.equals(String.valueOf(0xcafebabe))) {
63 pln("FAILED: wrong index: " + msg + ", should be: " + 0xcafebabe);
72 p("ArrayIndexOutOfBoundsException:");
73 int[] ia = new int[1];
76 } catch (ArrayIndexOutOfBoundsException e) {
77 String msg = e.getMessage();
79 if (msg == null || !msg.equals(String.valueOf(0xbabecafe))) {
80 pln("FAILED: wrong index: " + msg + ", should be: " + 0xbabecafe);
91 p("NegativeArraySizeException:");
92 int[] ia = new int[-1];
94 } catch (NegativeArraySizeException e) {
100 p("NegativeArraySizeException:");
101 int[] ia = new int[-1];
103 } catch (NegativeArraySizeException e) {
110 p("ClassCastException:");
111 Object o = new Object();
112 Integer i = (Integer) o;
114 } catch (ClassCastException e) {
119 p("ClassCastException:");
120 Object o = new Object();
124 } catch (ClassCastException e) {
131 p("ArithmeticException (only w/ -softnull):");
132 int i = 1, j = 0, k = i / j;
134 } catch (ArithmeticException e) {
135 String msg = e.getMessage();
137 if (msg == null || !msg.equals("/ by zero")) {
138 pln("FAILED: wrong message: " + msg + ", should be: / by zero");
147 p("ArithmeticException (only w/ -softnull):");
148 long i = 1, j = 0, k = i / j;
150 } catch (ArithmeticException e) {
151 String msg = e.getMessage();
153 if (msg == null || !msg.equals("/ by zero")) {
154 pln("FAILED: wrong message: " + msg + ", should be: / by zero");
164 p("OutOfMemoryError:");
165 /* 100 MB should be enough */
166 byte[] ba = new byte[100 * 1024 * 1024];
168 } catch (OutOfMemoryError e) {
174 p("OutOfMemoryError:");
175 /* 100 MB should be enough */
176 byte[] ba = new byte[100 * 1024 * 1024];
178 } catch (OutOfMemoryError e) {
185 p("NullPointerException (only w/ -softnull):");
189 } catch (NullPointerException e) {
195 p("NullPointerException (only w/ -softnull):");
199 } catch (NullPointerException e) {
207 pln("---------- some asmpart exceptions --------------");
210 p("NullPointerException in <clinit> (PUTSTATIC):");
211 extest_clinit_1.i = 1;
213 } catch (ExceptionInInitializerError e) {
214 if (e.getCause().getClass() != NullPointerException.class) {
223 p("NullPointerException in <clinit> (GETSTATIC):");
224 int i = extest_clinit_2.i;
226 } catch (ExceptionInInitializerError e) {
227 if (e.getCause().getClass() != NullPointerException.class) {
236 p("ArithmeticException (idiv):");
237 int i = 1, j = 0, k = i / j;
239 } catch (ArithmeticException e) {
245 p("ArithmeticException (ldiv):");
246 long i = 1, j = 0, k = i / j;
248 } catch (ArithmeticException e) {
254 p("ArithmeticException (irem):");
255 int i = 1, j = 0, k = i % j;
257 } catch (ArithmeticException e) {
263 p("ArithmeticException (lrem):");
264 long i = 1, j = 0, k = i % j;
266 } catch (ArithmeticException e) {
272 p("NullPointerException (aastore):");
274 oa[0] = new Object();
276 } catch (NullPointerException e) {
282 p("ArrayIndexOutOfBoundsException (aastore):");
283 Object[] oa = new Object[1];
284 oa[0xaa] = new Object();
286 } catch (ArrayIndexOutOfBoundsException e) {
287 String msg = e.getMessage();
289 if (msg == null || !msg.equals(String.valueOf(0xaa))) {
290 pln("FAILED: wrong index: " + msg + ", should be: " + 0xaa);
299 p("ArrayStoreException (aastore):");
300 Integer[] ia = new Integer[1];
301 Object[] oa = (Object[]) ia;
302 oa[0] = new Object();
304 } catch (ArrayStoreException e) {
310 p("ClassCastException (checkarraycast):");
311 Object[] oa = new Object[1];
312 Integer[] ia = (Integer[]) oa;
314 } catch (ClassCastException e) {
322 pln("---------- exception related things -------------");
325 p("load/link an exception class in asmpart:");
326 throw new Exception();
327 } catch (UnknownError e) {
328 /* this exception class MUST NOT be loaded before!!!
329 otherwise this test in useless */
330 } catch (Exception e) {
338 pln("---------- native stub exceptions ---------------");
341 p("NullPointerException (native):");
342 System.arraycopy(null, 1, null, 1, 1);
344 } catch (Exception e) {
349 // p("NullPointerException in <clinit>:");
350 // extest_clinit_3.sub();
352 // } catch (ExceptionInInitializerError e) {
360 pln("---------- no OK beyond this point --------------");
362 pln("NullPointerException (without catch):");
368 public synchronized static void sub() throws Exception {
372 public static void sub2() throws Exception {
376 public synchronized static void sub3() throws Exception {
380 public static void sub4() throws Exception {
381 throw new Exception();
384 public static void p(String s) {
386 for (int i = s.length(); i < 46; i++) {
387 System.out.print(" ");
391 public static void pln() {
392 System.out.println();
395 public static void pln(String s) {
396 System.out.println(s);
399 public static void pstacktrace(Throwable e) {
400 if (!printStackTrace) return;
401 System.out.println("================== Stacktrace");
403 System.out.println("Stacktrace ==================");
408 public class extest_clinit_1 {
417 public class extest_clinit_2 {
426 public class extest_clinit_3 {
432 public static native void sub();