2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / testsuite / libjava.lang / Throw_2.java
blob6d1d0e6b4490dc3857461f1187580baefbb9ef28
1 // Check that NullPointerExceptions thrown from library code are
2 // caught. This detects a number of failures that can be caused by
3 // libgcj being built incorrectly. In particular, we ensure that a
4 // SEGV in native (i.e. C++) code in libgcj is handled correctly.
6 // Regrettably, we cannot guarantee that Double.parseDouble() will
7 // always be native code, or that it will never be inlined. It could
8 // be argued that we should add a method to libgcj that will be
9 // guaranteed forever to be native, but I'm reluctant to add to the
10 // library for the sole purpose of performing this test.
12 public class Throw_2
14 public static Throwable obj()
16 return null;
19 public static String str()
21 return null;
24 static double d;
26 public static void main (String[] args)
28 // This NullPointerException will, at the time of writing, be
29 // thrown from Java code in libgcj.
30 try
32 java.util.Vector v = new java.util.Vector (null);
33 System.out.println ("fail: no exception thrown");
35 catch (NullPointerException _)
37 System.out.println ("1");
39 catch (Throwable _)
41 System.out.println ("fail: " + _);
43 // This one will, at the time of writing, be thrown from C++
44 // code in libgcj.
45 try
47 d = Double.parseDouble(str());
48 System.out.println ("fail: no exception thrown");
50 catch (NullPointerException _)
52 System.out.println ("2");
54 catch (Throwable _)
56 System.out.println ("fail: " + _);