source: trunk/gcc/libjava/testsuite/libjava.lang/Throw_2.java

Last change on this file was 1392, checked in by bird, 21 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.5 KB
Line 
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.
5
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.
11
12public class Throw_2
13{
14 public static Throwable obj()
15 {
16 return null;
17 }
18
19 public static String str()
20 {
21 return null;
22 }
23
24 static double d;
25
26 public static void main (String[] args)
27 {
28 // This NullPointerException will, at the time of writing, be
29 // thrown from Java code in libgcj.
30 try
31 {
32 java.util.Vector v = new java.util.Vector (null);
33 System.out.println ("fail: no exception thrown");
34 }
35 catch (NullPointerException _)
36 {
37 System.out.println ("1");
38 }
39 catch (Throwable _)
40 {
41 System.out.println ("fail: " + _);
42 }
43 // This one will, at the time of writing, be thrown from C++
44 // code in libgcj.
45 try
46 {
47 d = Double.parseDouble(str());
48 System.out.println ("fail: no exception thrown");
49 }
50 catch (NullPointerException _)
51 {
52 System.out.println ("2");
53 }
54 catch (Throwable _)
55 {
56 System.out.println ("fail: " + _);
57 }
58 }
59}
Note: See TracBrowser for help on using the repository browser.