1#!/bin/java bsh.Interpreter
2
3source("TestHarness.bsh");
4
5/**
6	Make sure that scripts can catch all of the runtime exceptions that we
7	might cause during the evaluation of script...
8
9	This means that these must be caught by us and wrapped in TargetException.
10
11	These haven't been done/checked yet:
12
13/pkg/java/src//java/lang/IllegalMonitorStateException.java
14/pkg/java/src//java/lang/InterruptedException.java
15
16*/
17
18// /pkg/java/src//java/lang/ArithmeticException.java
19try { int i=1/0; } catch ( ArithmeticException e ) { flag(); }
20
21// /pkg/java/src//java/lang/ClassCastException.java
22try { ((String)(new Object())); } catch ( ClassCastException e2 ) { flag(); }
23
24// Should *not* be able to catch ClassNotFoundException when class names are
25// used directly in the script.  These indicate a structural or missing class
26// in the expected environment and should cause evaluation to stop.
27// /pkg/java/src//java/lang/ClassNotFoundException
28assert( isEvalError("try { new Booga123(); } catch ( ClassNotFoundException e2 ) { }") );
29//
30// Should be able to catch real target ClassNotFoundException generated by
31// method calls that throw it.
32// Note: at time of writing Class.forName() doesn't see extended path and we'd
33// want getClass() instead.
34try { Class.forName("Booga123"); } catch ( ClassNotFoundException e2 ) { flag(); };
35
36/*
37// Shouldn't catch class not found indicating structural problems with
38// the script (e.g. typed var declaration, direct useage etc.)
39assert( isEvalError("try { Booga123 booga; } catch ( ClassNotFoundException e2 ) { }") );
40assert( isEvalError("try { Booga123.foo=5; } catch ( ClassNotFoundException e2 ) { }") );
41*/
42
43// /pkg/java/src//java/lang/ArrayIndexOutOfBoundsException.java
44try {
45	a=new String[5];
46	a[99];
47} catch ( ArrayIndexOutOfBoundsException e3 ) { flag(); }
48
49// /pkg/java/src//java/lang/NegativeArraySizeException.java
50try {
51	a=new String[-1];
52} catch ( NegativeArraySizeException e4 ) { flag(); }
53
54// /pkg/java/src//java/lang/ArrayStoreException.java
55try {
56	sa=new String[5];
57	sa[0] = new Integer(0);
58} catch ( ArrayStoreException e5 ) { flag(); }
59
60
61// /pkg/java/src//java/lang/NullPointerException.java
62try {
63	foo = null;
64	foo.bar;
65} catch ( NullPointerException e6 ) { flag(); }
66
67// /pkg/java/src//java/lang/NullPointerException.java
68try {
69	foo = null;
70	foo.bar();
71} catch ( NullPointerException e7) { flag(); }
72
73assert( flag() == 8 );
74
75complete();
76