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 _Exception(message); | 21 factory Exception([var message]) => new _Exception(message); |
22 } | 22 } |
23 | 23 |
24 | |
25 /** Default implementation of [Exception] which carries a message. */ | 24 /** Default implementation of [Exception] which carries a message. */ |
26 class _Exception implements Exception { | 25 class _Exception implements Exception { |
27 final message; | 26 final message; |
28 | 27 |
29 _Exception([this.message]); | 28 _Exception([this.message]); |
30 | 29 |
31 String toString() { | 30 String toString() { |
32 if (message == null) return "Exception"; | 31 if (message == null) return "Exception"; |
33 return "Exception: $message"; | 32 return "Exception: $message"; |
34 } | 33 } |
35 } | 34 } |
36 | 35 |
37 | |
38 /** | 36 /** |
39 * Exception thrown when a string or some other data does not have an expected | 37 * Exception thrown when a string or some other data does not have an expected |
40 * format and cannot be parsed or processed. | 38 * format and cannot be parsed or processed. |
41 */ | 39 */ |
42 class FormatException implements Exception { | 40 class FormatException implements Exception { |
43 /** | 41 /** |
44 * A message describing the format error. | 42 * A message describing the format error. |
45 */ | 43 */ |
46 final String message; | 44 final String message; |
47 | 45 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 int markOffset = offset - start + prefix.length; | 170 int markOffset = offset - start + prefix.length; |
173 return "$report$prefix$slice$postfix\n${" " * markOffset}^\n"; | 171 return "$report$prefix$slice$postfix\n${" " * markOffset}^\n"; |
174 } | 172 } |
175 } | 173 } |
176 | 174 |
177 // Exception thrown when doing integer division with a zero divisor. | 175 // Exception thrown when doing integer division with a zero divisor. |
178 class IntegerDivisionByZeroException implements Exception { | 176 class IntegerDivisionByZeroException implements Exception { |
179 const IntegerDivisionByZeroException(); | 177 const IntegerDivisionByZeroException(); |
180 String toString() => "IntegerDivisionByZeroException"; | 178 String toString() => "IntegerDivisionByZeroException"; |
181 } | 179 } |
OLD | NEW |