OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 throw statement | 4 // Dart test program for testing throw statement |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 abstract class TestException { | 8 abstract class TestException { |
9 String getMessage(); | 9 String getMessage(); |
10 } | 10 } |
11 | 11 |
12 class MyException implements TestException { | 12 class MyException implements TestException { |
13 const MyException([String message = ""]) : message_ = message; | 13 const MyException([String message = ""]) : message_ = message; |
14 String getMessage() { return message_; } | 14 String getMessage() { |
| 15 return message_; |
| 16 } |
| 17 |
15 final String message_; | 18 final String message_; |
16 } | 19 } |
17 | 20 |
18 class MyException2 implements TestException { | 21 class MyException2 implements TestException { |
19 const MyException2([String message = ""]) : message_ = message; | 22 const MyException2([String message = ""]) : message_ = message; |
20 String getMessage() { return message_; } | 23 String getMessage() { |
| 24 return message_; |
| 25 } |
| 26 |
21 final String message_; | 27 final String message_; |
22 } | 28 } |
23 | 29 |
24 class MyException3 implements TestException { | 30 class MyException3 implements TestException { |
25 const MyException3([String message = ""]) : message_ = message; | 31 const MyException3([String message = ""]) : message_ = message; |
26 String getMessage() { return message_; } | 32 String getMessage() { |
| 33 return message_; |
| 34 } |
| 35 |
27 final String message_; | 36 final String message_; |
28 } | 37 } |
29 | 38 |
30 class Helper { | 39 class Helper { |
31 static int f1(int i) { | 40 static int f1(int i) { |
32 try { | 41 try { |
33 int j; | 42 int j; |
34 j = func(); | 43 j = func(); |
35 if (j > 0) { | 44 if (j > 0) { |
36 throw new MyException2("Test for exception being thrown"); | 45 throw new MyException2("Test for exception being thrown"); |
(...skipping 27 matching lines...) Expand all Loading... |
64 | 73 |
65 class Throw1Test { | 74 class Throw1Test { |
66 static testMain() { | 75 static testMain() { |
67 Expect.equals(850, Helper.f1(1)); | 76 Expect.equals(850, Helper.f1(1)); |
68 } | 77 } |
69 } | 78 } |
70 | 79 |
71 main() { | 80 main() { |
72 Throw1Test.testMain(); | 81 Throw1Test.testMain(); |
73 } | 82 } |
OLD | NEW |