OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 // Dart test program for testing try/catch statement without any exceptions | |
5 // being thrown. | |
6 | |
7 interface TestException { | |
8 String getMessage(); | |
9 } | |
10 | |
11 class MyException implements TestException { | |
12 const MyException([String message = ""]) : this._message = message; | |
13 String getMessage() { return _message; } | |
14 final String _message; | |
15 } | |
16 | |
17 class MyParameterizedException<U, V> implements TestException { | |
18 const MyParameterizedException([String message = ""]) | |
19 : this._message = message; | |
20 String getMessage() { return _message; } | |
21 final String _message; | |
22 } | |
23 | |
24 class StackTrace { | |
25 StackTrace() { } | |
26 printStackTrace(TestException ex) { | |
27 print(ex); | |
28 } | |
29 } | |
30 | |
31 class Helper { | |
32 static int test1(int i) { | |
33 try { | |
34 int j; | |
35 j = f2(); | |
36 j = f3(); | |
37 try { | |
38 int k = f2(); | |
39 f3(); | |
40 } catch (MyException ex) { | |
41 int i = 10; | |
42 print(i); | |
43 } catch (TestException ex) { | |
44 int k = 10; | |
45 print(k); | |
46 } | |
47 try { | |
48 j = j + 24; | |
49 } catch (var e) { | |
50 i = 300; | |
51 print(e.getMessage()); | |
52 } | |
53 try { | |
54 j += 20; | |
55 } catch (final e) { | |
56 i = 400; | |
57 print(e.getMessage()); | |
58 } | |
59 try { | |
60 j += 40; | |
61 } catch (var e) { | |
62 i = 600; | |
63 print(e.getMessage()); | |
64 } | |
65 try { | |
66 j += 60; | |
67 } catch (var e, var trace) { | |
68 i = 700; | |
69 trace.printStackTrace(e); | |
70 print(e.getMessage()); | |
71 } | |
72 try { | |
73 j += 80; | |
74 } catch (final MyException e) { | |
75 i = 500; | |
76 print(e.getMessage()); | |
77 } | |
78 } catch (MyParameterizedException<String, TestException> e, var trace) { | |
79 i = 800; | |
80 trace.printStackTrace(e); | |
81 throw; | |
82 } catch (MyException exception) { | |
83 i = 100; | |
84 print(exception.getMessage()); | |
85 } catch (TestException e, StackTrace trace) { | |
86 i = 200; | |
87 trace.printStackTrace(e); | |
88 } finally { | |
89 i = 900; | |
90 } | |
91 return i; | |
92 } | |
93 | |
94 static int f2() { | |
95 return 2; | |
96 } | |
97 | |
98 static int f3() { | |
99 int i = 0; | |
100 while (i < 10) { | |
101 i++; | |
102 } | |
103 return i; | |
104 } | |
105 } | |
106 | |
107 class TryCatchTest { | |
108 static testMain() { | |
109 Expect.equals(900, Helper.test1(1)); | |
110 } | |
111 } | |
112 | |
113 main() { | |
114 TryCatchTest.testMain(); | |
115 } | |
OLD | NEW |