OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Dart test program for testing try/catch statement without any exceptions | 4 // Dart test program for testing try/catch statement without any exceptions |
5 // being thrown. | 5 // being thrown. |
6 | 6 |
7 interface TestException { | 7 interface TestException { |
8 String getMessage(); | 8 String getMessage(); |
9 } | 9 } |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 class Helper { | 31 class Helper { |
32 static int test1(int i) { | 32 static int test1(int i) { |
33 try { | 33 try { |
34 int j; | 34 int j; |
35 j = f2(); | 35 j = f2(); |
36 j = f3(); | 36 j = f3(); |
37 try { | 37 try { |
38 int k = f2(); | 38 int k = f2(); |
39 f3(); | 39 f3(); |
40 } catch (MyException ex) { | 40 } on MyException catch (ex) { |
41 int i = 10; | 41 int i = 10; |
42 print(i); | 42 print(i); |
43 } catch (TestException ex) { | 43 } on TestException catch (ex) { |
44 int k = 10; | 44 int k = 10; |
45 print(k); | 45 print(k); |
46 } | 46 } |
47 try { | 47 try { |
48 j = j + 24; | 48 j = j + 24; |
49 } catch (var e) { | 49 } catch (e) { |
50 i = 300; | 50 i = 300; |
51 print(e.getMessage()); | 51 print(e.getMessage()); |
52 } | 52 } |
53 try { | 53 try { |
54 j += 20; | 54 j += 20; |
55 } catch (final e) { | 55 } catch (e) { |
56 i = 400; | 56 i = 400; |
57 print(e.getMessage()); | 57 print(e.getMessage()); |
58 } | 58 } |
59 try { | 59 try { |
60 j += 40; | 60 j += 40; |
61 } catch (var e) { | 61 } catch (e) { |
62 i = 600; | 62 i = 600; |
63 print(e.getMessage()); | 63 print(e.getMessage()); |
64 } | 64 } |
65 try { | 65 try { |
66 j += 60; | 66 j += 60; |
67 } catch (var e, var trace) { | 67 } catch (e, trace) { |
68 i = 700; | 68 i = 700; |
69 trace.printStackTrace(e); | 69 trace.printStackTrace(e); |
70 print(e.getMessage()); | 70 print(e.getMessage()); |
71 } | 71 } |
72 try { | 72 try { |
73 j += 80; | 73 j += 80; |
74 } catch (final MyException e) { | 74 } on MyException catch (e) { |
75 i = 500; | 75 i = 500; |
76 print(e.getMessage()); | 76 print(e.getMessage()); |
77 } | 77 } |
78 } catch (MyParameterizedException<String, TestException> e, var trace) { | 78 } on MyParameterizedException<String, TestException> catch (e, trace) { |
79 i = 800; | 79 i = 800; |
80 trace.printStackTrace(e); | 80 trace.printStackTrace(e); |
81 throw; | 81 throw; |
82 } catch (MyException exception) { | 82 } on MyException catch (exception) { |
83 i = 100; | 83 i = 100; |
84 print(exception.getMessage()); | 84 print(exception.getMessage()); |
85 } catch (TestException e, StackTrace trace) { | 85 } on TestException catch (e, trace) { |
86 i = 200; | 86 i = 200; |
87 trace.printStackTrace(e); | 87 trace.printStackTrace(e); |
88 } finally { | 88 } finally { |
89 i = 900; | 89 i = 900; |
90 } | 90 } |
91 return i; | 91 return i; |
92 } | 92 } |
93 | 93 |
94 static int f2() { | 94 static int f2() { |
95 return 2; | 95 return 2; |
(...skipping 10 matching lines...) Expand all Loading... |
106 | 106 |
107 class TryCatchTest { | 107 class TryCatchTest { |
108 static testMain() { | 108 static testMain() { |
109 Expect.equals(900, Helper.test1(1)); | 109 Expect.equals(900, Helper.test1(1)); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 main() { | 113 main() { |
114 TryCatchTest.testMain(); | 114 TryCatchTest.testMain(); |
115 } | 115 } |
OLD | NEW |