History

Added ExceptionsTest

Dmitry Kabak (userdima committed 13 years ago

Commit eff203a1 parent 489be662 files · +61 −1Browse files

Showing the changes to java/tests (2 of 2 files). Show all

Unified · Split

2 files
  1. java/tests/ExceptionsTest.java +59 −0
  2. java/tests/mkfile +2 −1
java/tests/ExceptionsTest.java+59−0
@@ -0,0 +1,59 @@
1+
2+import static utils.Utils.*;
3+
4+public class ExceptionsTest {
5+
6+ public static void strictFunction(Integer arg) {
7+ try {
8+ int number = arg;
9+ if (number < 0)
10+ throw new IllegalArgumentException("we do not accept negatives");
11+ System.out.println("Whee, strictFunction call is complete!");
12+ }
13+ catch (NullPointerException e) {
14+ System.out.println("Null pointer exception caught: " + e.getMessage());
15+ }
16+ catch (IllegalArgumentException e) {
17+ System.out.println("Illegal argument exception caught: " + e.getMessage());
18+ if (arg == -42)
19+ throw new RuntimeException("the negative answer is awful");
20+ }
21+ finally {
22+ System.out.println("strictFunction finally");
23+ if (arg != null && arg == 42)
24+ throw new RuntimeException("the answer is not accepted");
25+ }
26+ }
27+
28+ public static void main(String[] args) {
29+ System.out.println("Simple test");
30+ System.out.println("Before exception");
31+ try {
32+ System.out.println("In try block");
33+ throw new IllegalArgumentException();
34+ }
35+ catch (IllegalArgumentException e) {
36+ System.out.println("Exception caught");
37+ }
38+ finally {
39+ System.out.println("Clean up");
40+ }
41+ System.out.println("After exception");
42+
43+ System.out.println("Extendend test");
44+ strictFunction(null);
45+ strictFunction(-1);
46+ try {
47+ strictFunction(42);
48+ }
49+ catch (RuntimeException e) {
50+ System.out.println("Runtime exception caught: " + e.getMessage());
51+ }
52+ try {
53+ strictFunction(-42);
54+ }
55+ catch (RuntimeException e) {
56+ System.out.println("Runtime exception caught: " + e.getMessage());
57+ }
58+ }
59+}
java/tests/mkfile+2−1
@@ -5,6 +5,7 @@ TESTS= SystemIOTest\ · 4 unmodified lines
55 MathTest\
66 InnerClassTest\
77 ThreadTest\
8+ ExceptionsTest\
89
910 OBJ=${TESTS:%=test-%}
1011 JAVAC=os -d $ROOT`{pwd} javac
@@ -16,7 +17,7 @@ utils:QV: · 5 unmodified lines
1617
1718 test-%:QV:
1819 $JAVAC $stem.java
19− for c in $stem*.class {java/j2d -g $c}
20+ for c in $stem*.class {java/j2d -g $c; java/j2d -pvS $c}
2021 java/jvm $stem
2122 echo $stem passed!
2223