summaryrefslogtreecommitdiff
path: root/libjava/testsuite/libjava.lang/Throw_2.java
blob: 6d1d0e6b4490dc3857461f1187580baefbb9ef28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Check that NullPointerExceptions thrown from library code are
// caught.  This detects a number of failures that can be caused by
// libgcj being built incorrectly.  In particular, we ensure that a
// SEGV in native (i.e. C++) code in libgcj is handled correctly.

// Regrettably, we cannot guarantee that Double.parseDouble() will
// always be native code, or that it will never be inlined.  It could
// be argued that we should add a method to libgcj that will be
// guaranteed forever to be native, but I'm reluctant to add to the
// library for the sole purpose of performing this test.

public class Throw_2
{
  public static Throwable obj()
    {
      return null;
    }

  public static String str()
    {
      return null;
    }

  static double d;

  public static void main (String[] args)
    {
      // This NullPointerException will, at the time of writing, be
      // thrown from Java code in libgcj.
      try
	{
	  java.util.Vector v = new java.util.Vector (null);
	  System.out.println ("fail: no exception thrown");
	}
      catch (NullPointerException _)
	{
	  System.out.println ("1");
	}
      catch (Throwable _)
	{
	  System.out.println ("fail: " + _);
	}
      // This one will, at the time of writing, be thrown from C++
      // code in libgcj.
      try
	{
	  d = Double.parseDouble(str());
	  System.out.println ("fail: no exception thrown");
	}
      catch (NullPointerException _)
	{
	  System.out.println ("2");
	}
      catch (Throwable _)
	{
	  System.out.println ("fail: " + _);
	}
    }
}