| 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 236 |
| 237 // TODO(lrn): This constructor should be called only with string values. | 237 // TODO(lrn): This constructor should be called only with string values. |
| 238 // It currently isn't in all cases. | 238 // It currently isn't in all cases. |
| 239 /** | 239 /** |
| 240 * Create a new [RangeError] with the given [message]. | 240 * Create a new [RangeError] with the given [message]. |
| 241 */ | 241 */ |
| 242 RangeError(var message) | 242 RangeError(var message) |
| 243 : invalidValue = null, start = null, end = null, super(message); | 243 : invalidValue = null, start = null, end = null, super(message); |
| 244 | 244 |
| 245 /** Create a new [RangeError] with a message for the given [value]. */ | 245 /** Create a new [RangeError] with a message for the given [value]. */ |
| 246 RangeError.value(num value, [String message = "Value not in range"]) | 246 RangeError.value(num value, [String message]) |
| 247 : invalidValue = value, start = null, end = null, | 247 : invalidValue = value, start = null, end = null, |
| 248 super(message); | 248 super(message != null ? message : "Value not in range"); |
| 249 | 249 |
| 250 /** | 250 /** |
| 251 * Create a new [RangeError] with for an invalid value being outside a range. | 251 * Create a new [RangeError] with for an invalid value being outside a range. |
| 252 * | 252 * |
| 253 * The allowed range is from [start] to [end], inclusive. | 253 * The allowed range is from [start] to [end], inclusive. |
| 254 * If `start` or `end` are `null`, the range is infinite in that direction. | 254 * If `start` or `end` are `null`, the range is infinite in that direction. |
| 255 * | 255 * |
| 256 * For a range from 0 to the length of something, end exclusive, use | 256 * For a range from 0 to the length of something, end exclusive, use |
| 257 * [RangeError.index]. | 257 * [RangeError.index]. |
| 258 */ | 258 */ |
| 259 RangeError.range(this.invalidValue, this.start, this.end, | 259 RangeError.range(this.invalidValue, this.start, this.end, [String message]) |
| 260 [String message = "Invalid value"]) : super(message); | 260 : super(message != null ? message : "Invalid value"); |
| 261 | 261 |
| 262 /** | 262 /** |
| 263 * Creates a new [RangeError] stating that [index] is not a valid index | 263 * Creates a new [RangeError] stating that [index] is not a valid index |
| 264 * into [indexable]. | 264 * into [indexable]. |
| 265 * | 265 * |
| 266 * The [length] is the length of [indexable] at the time of the error. | 266 * The [length] is the length of [indexable] at the time of the error. |
| 267 * If `length` is omitted, it defaults to `indexable.length`. | 267 * If `length` is omitted, it defaults to `indexable.length`. |
| 268 * | 268 * |
| 269 * The message is used as part of the string representation of the error. | 269 * The message is used as part of the string representation of the error. |
| 270 */ | 270 */ |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 310 |
| 311 /** | 311 /** |
| 312 * Creates a new [IndexError] stating that [invalidValue] is not a valid index | 312 * Creates a new [IndexError] stating that [invalidValue] is not a valid index |
| 313 * into [indexable]. | 313 * into [indexable]. |
| 314 * | 314 * |
| 315 * The [length] is the length of [indexable] at the time of the error. | 315 * The [length] is the length of [indexable] at the time of the error. |
| 316 * If `length` is omitted, it defaults to `indexable.length`. | 316 * If `length` is omitted, it defaults to `indexable.length`. |
| 317 * | 317 * |
| 318 * The message is used as part of the string representation of the error. | 318 * The message is used as part of the string representation of the error. |
| 319 */ | 319 */ |
| 320 IndexError(this.invalidValue, indexable, | 320 IndexError(this.invalidValue, indexable, [String message, int length]) |
| 321 [String message = "Index out of range", int length]) | |
| 322 : this.indexable = indexable, | 321 : this.indexable = indexable, |
| 323 this.length = (length != null) ? length : indexable.length, | 322 this.length = (length != null) ? length : indexable.length, |
| 324 super(message); | 323 super(message != null ? message : "Index out of range"); |
| 325 | 324 |
| 326 // Getters inherited from RangeError. | 325 // Getters inherited from RangeError. |
| 327 int get start => 0; | 326 int get start => 0; |
| 328 int get end => length - 1; | 327 int get end => length - 1; |
| 329 | 328 |
| 330 String toString() { | 329 String toString() { |
| 331 String target = Error.safeToString(indexable); | 330 String target = Error.safeToString(indexable); |
| 332 if (invalidValue < 0) { | 331 if (invalidValue < 0) { |
| 333 return "RangeError: $message ($target[$invalidValue]): " | 332 return "RangeError: $message ($target[$invalidValue]): " |
| 334 "index must not be negative."; | 333 "index must not be negative."; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 * the first time it is read. If evaluating the initializer expression causes | 498 * the first time it is read. If evaluating the initializer expression causes |
| 500 * another read of the variable, this error is thrown. | 499 * another read of the variable, this error is thrown. |
| 501 */ | 500 */ |
| 502 class CyclicInitializationError extends Error { | 501 class CyclicInitializationError extends Error { |
| 503 final String variableName; | 502 final String variableName; |
| 504 CyclicInitializationError([this.variableName]); | 503 CyclicInitializationError([this.variableName]); |
| 505 String toString() => variableName == null | 504 String toString() => variableName == null |
| 506 ? "Reading static variable during its initialization" | 505 ? "Reading static variable during its initialization" |
| 507 : "Reading static variable '$variableName' during its initialization"; | 506 : "Reading static variable '$variableName' during its initialization"; |
| 508 } | 507 } |
| OLD | NEW |