| 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 // Exceptions are thrown either by the VM or from Dart code. | 5 // Exceptions are thrown either by the VM or from Dart code. |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Interface implemented by all core library exceptions. | 8 * Interface implemented by all core library exceptions. |
| 9 * Defaults to an implementation that only carries a simple message. | 9 * Defaults to an implementation that only carries a simple message. |
| 10 */ | 10 */ |
| 11 interface Exception default _ExceptionImplementation { | 11 interface Exception default ExceptionImplementation { |
| 12 // TODO(lrn): This should be an abstract class, but we don't yet support | |
| 13 // redirecting factory constructors. | |
| 14 const Exception([var message]); | 12 const Exception([var message]); |
| 15 } | 13 } |
| 16 | 14 |
| 17 | 15 |
| 18 /** Default implementation of [Exception] which carries a message. */ | |
| 19 class _ExceptionImplementation implements Exception { | |
| 20 final message; | |
| 21 const _ExceptionImplementation([this.message]); | |
| 22 String toString() => (message == null) ? "Exception" : "Exception: $message"; | |
| 23 } | |
| 24 | |
| 25 | |
| 26 /** | 16 /** |
| 27 * Exception thrown because of an index outside of the valid range. | 17 * Exception thrown because of an index outside of the valid range. |
| 28 */ | 18 */ |
| 29 class IndexOutOfRangeException implements Exception { | 19 class IndexOutOfRangeException implements Exception { |
| 30 const IndexOutOfRangeException(this._value); | 20 const IndexOutOfRangeException(this._value); |
| 31 | 21 |
| 32 String toString() => "IndexOutOfRangeException: $_value"; | 22 String toString() => "IndexOutOfRangeException: $_value"; |
| 33 | 23 |
| 34 final _value; | 24 final _value; |
| 35 } | 25 } |
| 36 | 26 |
| 27 |
| 37 /** | 28 /** |
| 38 * Exception thrown because of attempt to modify an immutable object. | 29 * Exception thrown because of attempt to modify an immutable object. |
| 39 */ | 30 */ |
| 40 class IllegalAccessException implements Exception { | 31 class IllegalAccessException implements Exception { |
| 41 const IllegalAccessException(); | 32 const IllegalAccessException(); |
| 42 String toString() => "Attempt to modify an immutable object"; | 33 String toString() => "Attempt to modify an immutable object"; |
| 43 } | 34 } |
| 44 | 35 |
| 45 | 36 |
| 46 class ClosureArgumentMismatchException implements Exception { | 37 class ClosureArgumentMismatchException implements Exception { |
| 47 const ClosureArgumentMismatchException(); | 38 const ClosureArgumentMismatchException(); |
| 48 String toString() => "Closure argument mismatch"; | 39 String toString() => "Closure argument mismatch"; |
| 49 } | 40 } |
| 50 | 41 |
| 51 | 42 |
| 52 class ObjectNotClosureException implements Exception { | 43 class ObjectNotClosureException implements Exception { |
| 53 const ObjectNotClosureException(); | 44 const ObjectNotClosureException(); |
| 54 String toString() => "Object is not closure"; | 45 String toString() => "Object is not closure"; |
| 55 } | 46 } |
| 56 | 47 |
| 57 | 48 |
| 49 class OutOfMemoryException implements Exception { |
| 50 const OutOfMemoryException(); |
| 51 String toString() => "Out of Memory"; |
| 52 } |
| 53 |
| 54 |
| 58 class StackOverflowException implements Exception { | 55 class StackOverflowException implements Exception { |
| 59 const StackOverflowException(); | 56 const StackOverflowException(); |
| 60 String toString() => "Stack Overflow"; | 57 String toString() => "Stack Overflow"; |
| 61 } | 58 } |
| 62 | 59 |
| 63 | 60 |
| 64 /** | 61 /** |
| 65 * Exception thrown when a string or some other data does not have an expected | 62 * Exception thrown when a string or some other data does not have an expected |
| 66 * format and cannot be parsed or processed. | 63 * format and cannot be parsed or processed. |
| 67 */ | 64 */ |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 144 } |
| 148 | 145 |
| 149 /** | 146 /** |
| 150 * Exception thrown when a runtime error occurs. | 147 * Exception thrown when a runtime error occurs. |
| 151 */ | 148 */ |
| 152 class RuntimeError implements Exception { | 149 class RuntimeError implements Exception { |
| 153 final message; | 150 final message; |
| 154 RuntimeError(this.message); | 151 RuntimeError(this.message); |
| 155 String toString() => "RuntimeError: $message"; | 152 String toString() => "RuntimeError: $message"; |
| 156 } | 153 } |
| OLD | NEW |