Chromium Code Reviews| 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 { |
|
Mads Ager (google)
2012/10/19 11:24:27
Can you make this an abstract class or does that i
Lasse Reichstein Nielsen
2012/10/19 12:15:04
Comment added to explain why it's not done yet.
| |
| 12 const Exception([var message]); | 12 const Exception([var message]); |
| 13 } | 13 } |
| 14 | 14 |
| 15 | 15 |
| 16 /** Default implementation of [Exception] which carries a message. */ | |
| 17 class ExceptionImplementation implements Exception { | |
|
Mads Ager (google)
2012/10/19 11:24:27
This doesn't seem useful in itself? Make it privat
Lasse Reichstein Nielsen
2012/10/19 12:15:04
True. It's so simple that anybody who needs the in
| |
| 18 final message; | |
| 19 const ExceptionImplementation([this.message]); | |
| 20 String toString() => (message == null) ? "Exception" : "Exception: $message"; | |
| 21 } | |
| 22 | |
| 23 | |
| 16 /** | 24 /** |
| 17 * Exception thrown because of an index outside of the valid range. | 25 * Exception thrown because of an index outside of the valid range. |
| 18 */ | 26 */ |
| 19 class IndexOutOfRangeException implements Exception { | 27 class IndexOutOfRangeException implements Exception { |
| 20 const IndexOutOfRangeException(this._value); | 28 const IndexOutOfRangeException(this._value); |
| 21 | 29 |
| 22 String toString() => "IndexOutOfRangeException: $_value"; | 30 String toString() => "IndexOutOfRangeException: $_value"; |
| 23 | 31 |
| 24 final _value; | 32 final _value; |
| 25 } | 33 } |
| 26 | 34 |
| 27 | |
| 28 /** | 35 /** |
| 29 * Exception thrown because of attempt to modify an immutable object. | 36 * Exception thrown because of attempt to modify an immutable object. |
| 30 */ | 37 */ |
| 31 class IllegalAccessException implements Exception { | 38 class IllegalAccessException implements Exception { |
| 32 const IllegalAccessException(); | 39 const IllegalAccessException(); |
| 33 String toString() => "Attempt to modify an immutable object"; | 40 String toString() => "Attempt to modify an immutable object"; |
| 34 } | 41 } |
| 35 | 42 |
| 36 | 43 |
| 37 class ClosureArgumentMismatchException implements Exception { | 44 class ClosureArgumentMismatchException implements Exception { |
| 38 const ClosureArgumentMismatchException(); | 45 const ClosureArgumentMismatchException(); |
| 39 String toString() => "Closure argument mismatch"; | 46 String toString() => "Closure argument mismatch"; |
| 40 } | 47 } |
| 41 | 48 |
| 42 | 49 |
| 43 class ObjectNotClosureException implements Exception { | 50 class ObjectNotClosureException implements Exception { |
| 44 const ObjectNotClosureException(); | 51 const ObjectNotClosureException(); |
| 45 String toString() => "Object is not closure"; | 52 String toString() => "Object is not closure"; |
| 46 } | 53 } |
| 47 | 54 |
| 48 | 55 |
| 49 class OutOfMemoryException implements Exception { | |
| 50 const OutOfMemoryException(); | |
| 51 String toString() => "Out of Memory"; | |
| 52 } | |
| 53 | |
| 54 | |
| 55 class StackOverflowException implements Exception { | 56 class StackOverflowException implements Exception { |
| 56 const StackOverflowException(); | 57 const StackOverflowException(); |
| 57 String toString() => "Stack Overflow"; | 58 String toString() => "Stack Overflow"; |
| 58 } | 59 } |
| 59 | 60 |
| 60 | 61 |
| 61 /** | 62 /** |
| 62 * Exception thrown when a string or some other data does not have an expected | 63 * Exception thrown when a string or some other data does not have an expected |
| 63 * format and cannot be parsed or processed. | 64 * format and cannot be parsed or processed. |
| 64 */ | 65 */ |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 } | 145 } |
| 145 | 146 |
| 146 /** | 147 /** |
| 147 * Exception thrown when a runtime error occurs. | 148 * Exception thrown when a runtime error occurs. |
| 148 */ | 149 */ |
| 149 class RuntimeError implements Exception { | 150 class RuntimeError implements Exception { |
| 150 final message; | 151 final message; |
| 151 RuntimeError(this.message); | 152 RuntimeError(this.message); |
| 152 String toString() => "RuntimeError: $message"; | 153 String toString() => "RuntimeError: $message"; |
| 153 } | 154 } |
| OLD | NEW |