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 throw statement | |
5 | |
6 class MyException1 { | |
7 const MyException1([String message = "1"]) : message_ = message; | |
8 final String message_; | |
9 } | |
10 | |
11 class MyException2 { | |
12 const MyException2([String message = "2"]) : message_ = message; | |
13 final String message_; | |
14 } | |
15 | |
16 class MyException3 { | |
17 const MyException3([String message = "3"]) : message_ = message; | |
18 final String message_; | |
19 } | |
20 | |
21 class Helper { | |
22 static int f1(int i) { | |
23 try { | |
24 int j; | |
25 j = func(); | |
26 } catch (MyException3 exception) { | |
27 i = 300; | |
28 print(exception.message_); | |
29 } catch (MyException2 exception) { | |
30 i = 200; | |
31 print(exception.message_); | |
32 } catch (MyException1 exception) { | |
33 i = 100; | |
34 print(exception.message_); | |
35 } finally { | |
36 i = i + 800; | |
37 } | |
38 return i; | |
39 } | |
40 | |
41 // No catch in the same function for the type of exception being thrown | |
42 // in the try block here. We expect the handler if checks to fall thru and | |
43 // implicit rethrow to happen. | |
44 static int func() { | |
45 int i = 0; | |
46 try { | |
47 while (i < 10) { | |
48 i++; | |
49 } | |
50 if (i > 0) { | |
51 throw new MyException1("Test for MyException1 being thrown"); | |
52 } | |
53 } catch (MyException3 exception) { | |
54 i = 300; | |
55 print(exception.message_); | |
56 } catch (MyException2 exception) { | |
57 i = 200; | |
58 print(exception.message_); | |
59 } | |
60 return i; | |
61 } | |
62 } | |
63 | |
64 class Throw5Test { | |
65 static testMain() { | |
66 Expect.equals(900, Helper.f1(1)); | |
67 } | |
68 } | |
69 | |
70 main() { | |
71 Throw5Test.testMain(); | |
72 } | |
OLD | NEW |