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 /** | 7 /** |
8 * Error objects thrown in the case of a program failure. | 8 * Error objects thrown in the case of a program failure. |
9 * | 9 * |
10 * An `Error` object represents a program failure that the programmer | 10 * An `Error` object represents a program failure that the programmer |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 */ | 115 */ |
116 class NullThrownError extends Error { | 116 class NullThrownError extends Error { |
117 String toString() => "Throw of null."; | 117 String toString() => "Throw of null."; |
118 } | 118 } |
119 | 119 |
120 /** | 120 /** |
121 * Error thrown when a function is passed an unacceptable argument. | 121 * Error thrown when a function is passed an unacceptable argument. |
122 */ | 122 */ |
123 class ArgumentError extends Error { | 123 class ArgumentError extends Error { |
124 /** Whether value was provided. */ | 124 /** Whether value was provided. */ |
125 final bool _hasValue; | 125 final bool _hasValue; |
Søren Gjesse
2015/02/24 12:09:45
Initialize this to false?
Lasse Reichstein Nielsen
2015/02/24 14:16:22
It's a final variable, I'm sure it is initialized
| |
126 /** The invalid value. */ | 126 /** The invalid value. */ |
127 final invalidValue; | 127 final invalidValue; |
128 /** Name of the invalid argument, if available. */ | 128 /** Name of the invalid argument, if available. */ |
129 final String name; | 129 final String name; |
130 /** Message describing the problem. */ | 130 /** Message describing the problem. */ |
131 final message; | 131 final message; |
132 | 132 |
133 /** | 133 /** |
134 * The [message] describes the erroneous argument. | 134 * The [message] describes the erroneous argument. |
135 * | 135 * |
(...skipping 28 matching lines...) Expand all Loading... | |
164 /** | 164 /** |
165 * Create an argument error for a `null` argument that must not be `null`. | 165 * Create an argument error for a `null` argument that must not be `null`. |
166 * | 166 * |
167 * Shorthand for calling [ArgumentError.value] with a `null` value and a | 167 * Shorthand for calling [ArgumentError.value] with a `null` value and a |
168 * message of `"Must not be null"`. | 168 * message of `"Must not be null"`. |
169 */ | 169 */ |
170 ArgumentError.notNull([String name]) | 170 ArgumentError.notNull([String name]) |
171 : this.value(null, name, "Must not be null"); | 171 : this.value(null, name, "Must not be null"); |
172 | 172 |
173 // Helper functions for toString overridden in subclasses. | 173 // Helper functions for toString overridden in subclasses. |
174 String get _errorName => "Invalid argument${name == null ? "(s)" : ""}"; | 174 String get _errorName => "Invalid argument${!_hasValue ? "(s)" : ""}"; |
175 String get _errorExplanation => ""; | 175 String get _errorExplanation => ""; |
176 | 176 |
177 String toString() { | 177 String toString() { |
178 String nameString = ""; | 178 String nameString = ""; |
179 if (name != null) { | 179 if (name != null) { |
180 nameString = " ($name)"; | 180 nameString = " ($name)"; |
181 } | 181 } |
182 var message = this.message == null ? "" : ": ${this.message}"; | 182 var message = (this.message == null) ? "" : ": ${this.message}"; |
183 String prefix = "$_errorName$nameString$message"; | 183 String prefix = "$_errorName$nameString$message"; |
184 if (invalidValue == null) return prefix; | 184 if (!_hasValue) return prefix; |
185 // If we know the invalid value, we can try to describe the problem. | 185 // If we know the invalid value, we can try to describe the problem. |
186 String explanation = _errorExplanation; | 186 String explanation = _errorExplanation; |
187 String errorValue = Error.safeToString(invalidValue); | 187 String errorValue = Error.safeToString(invalidValue); |
188 return "$prefix$explanation: $errorValue"; | 188 return "$prefix$explanation: $errorValue"; |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 /** | 192 /** |
193 * Error thrown due to an index being outside a valid range. | 193 * Error thrown due to an index being outside a valid range. |
194 */ | 194 */ |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 * the first time it is read. If evaluating the initializer expression causes | 559 * the first time it is read. If evaluating the initializer expression causes |
560 * another read of the variable, this error is thrown. | 560 * another read of the variable, this error is thrown. |
561 */ | 561 */ |
562 class CyclicInitializationError extends Error { | 562 class CyclicInitializationError extends Error { |
563 final String variableName; | 563 final String variableName; |
564 CyclicInitializationError([this.variableName]); | 564 CyclicInitializationError([this.variableName]); |
565 String toString() => variableName == null | 565 String toString() => variableName == null |
566 ? "Reading static variable during its initialization" | 566 ? "Reading static variable during its initialization" |
567 : "Reading static variable '$variableName' during its initialization"; | 567 : "Reading static variable '$variableName' during its initialization"; |
568 } | 568 } |
OLD | NEW |