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 | 4 |
5 part of dart.core; | 5 part of dart.core; |
6 | 6 |
7 // Exceptions are thrown either by the VM or from Dart code. | 7 // Exceptions are thrown either by the VM or from Dart code. |
8 | 8 |
9 /** | 9 /** |
10 * A marker interface implemented by all core library exceptions. | 10 * A marker interface implemented by all core library exceptions. |
11 * | 11 * |
12 * An [Exception] is intended to convey information to the user about a failure, | 12 * An [Exception] is intended to convey information to the user about a failure, |
13 * so that the error can be addressed programmatically. It is intended to be | 13 * so that the error can be addressed programmatically. It is intended to be |
14 * caught, and it should contain useful data fields. | 14 * caught, and it should contain useful data fields. |
15 * | 15 * |
16 * Creating instances of [Exception] directly with [:new Exception("message"):] | 16 * Creating instances of [Exception] directly with [:new Exception("message"):] |
17 * is discouraged, and only included as a temporary measure during development, | 17 * is discouraged, and only included as a temporary measure during development, |
18 * until the actual exceptions used by a library are done. | 18 * until the actual exceptions used by a library are done. |
19 */ | 19 */ |
20 abstract class Exception { | 20 abstract class Exception { |
21 factory Exception([var message]) => new _ExceptionImplementation(message); | 21 factory Exception([var message]) => new _Exception(message); |
22 } | 22 } |
23 | 23 |
24 | 24 |
25 /** Default implementation of [Exception] which carries a message. */ | 25 /** Default implementation of [Exception] which carries a message. */ |
26 class _ExceptionImplementation implements Exception { | 26 class _Exception implements Exception { |
27 final message; | 27 final message; |
28 | 28 |
29 _ExceptionImplementation([this.message]); | 29 _Exception([this.message]); |
30 | 30 |
31 String toString() { | 31 String toString() { |
32 if (message == null) return "Exception"; | 32 if (message == null) return "Exception"; |
33 return "Exception: $message"; | 33 return "Exception: $message"; |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 | 37 |
38 /** | 38 /** |
39 * Exception thrown when a string or some other data does not have an expected | 39 * Exception thrown when a string or some other data does not have an expected |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 end = offset + 36; | 167 end = offset + 36; |
168 prefix = postfix = "..."; | 168 prefix = postfix = "..."; |
169 } | 169 } |
170 } | 170 } |
171 String slice = source.substring(start, end); | 171 String slice = source.substring(start, end); |
172 int markOffset = offset - start + prefix.length; | 172 int markOffset = offset - start + prefix.length; |
173 return "$report$prefix$slice$postfix\n${" " * markOffset}^\n"; | 173 return "$report$prefix$slice$postfix\n${" " * markOffset}^\n"; |
174 } | 174 } |
175 } | 175 } |
176 | 176 |
| 177 // Exception thrown when doing integer division with a zero divisor. |
177 class IntegerDivisionByZeroException implements Exception { | 178 class IntegerDivisionByZeroException implements Exception { |
178 const IntegerDivisionByZeroException(); | 179 const IntegerDivisionByZeroException(); |
179 String toString() => "IntegerDivisionByZeroException"; | 180 String toString() => "IntegerDivisionByZeroException"; |
180 } | 181 } |
OLD | NEW |