| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Exceptions are thrown either by the VM or from Dart code. | |
| 6 | |
| 7 /** | |
| 8 * Interface implemented by all core library exceptions. | |
| 9 */ | |
| 10 interface Exception default ExceptionImplementation { | |
| 11 const Exception([var msg]); | |
| 12 } | |
| 13 | |
| 14 | |
| 15 /** | |
| 16 * Exception thrown because of an index outside of the valid range. | |
| 17 */ | |
| 18 class IndexOutOfRangeException implements Exception { | |
| 19 const IndexOutOfRangeException(this._value); | |
| 20 | |
| 21 String toString() => "IndexOutOfRangeException: $_value"; | |
| 22 | |
| 23 final _value; | |
| 24 } | |
| 25 | |
| 26 | |
| 27 /** | |
| 28 * Exception thrown because of attempt to modify an immutable object. | |
| 29 */ | |
| 30 class IllegalAccessException implements Exception { | |
| 31 const IllegalAccessException(); | |
| 32 String toString() => "Attempt to modify an immutable object"; | |
| 33 } | |
| 34 | |
| 35 | |
| 36 /** | |
| 37 * Exception thrown because of non-existing receiver's method. | |
| 38 */ | |
| 39 class NoSuchMethodException implements Exception { | |
| 40 const NoSuchMethodException(Object this._receiver, | |
| 41 String this._functionName, | |
| 42 List this._arguments, | |
| 43 [List existingArgumentNames = null]) | |
| 44 : this._existingArgumentNames = existingArgumentNames; | |
| 45 | |
| 46 String toString() { | |
| 47 StringBuffer sb = new StringBuffer(); | |
| 48 for (int i = 0; i < _arguments.length; i++) { | |
| 49 if (i > 0) { | |
| 50 sb.add(", "); | |
| 51 } | |
| 52 sb.add(_arguments[i]); | |
| 53 } | |
| 54 if (_existingArgumentNames === null) { | |
| 55 return "NoSuchMethodException : method not found: '$_functionName'\n" | |
| 56 "Receiver: $_receiver\n" | |
| 57 "Arguments: [$sb]"; | |
| 58 } else { | |
| 59 String actualParameters = sb.toString(); | |
| 60 sb = new StringBuffer(); | |
| 61 for (int i = 0; i < _existingArgumentNames.length; i++) { | |
| 62 if (i > 0) { | |
| 63 sb.add(", "); | |
| 64 } | |
| 65 sb.add(_existingArgumentNames[i]); | |
| 66 } | |
| 67 String formalParameters = sb.toString(); | |
| 68 return "NoSuchMethodException: incorrect number of arguments passed to " | |
| 69 "method named '$_functionName'\nReceiver: $_receiver\n" | |
| 70 "Tried calling: $_functionName($actualParameters)\n" | |
| 71 "Found: $_functionName($formalParameters)"; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 final Object _receiver; | |
| 76 final String _functionName; | |
| 77 final List _arguments; | |
| 78 final List _existingArgumentNames; | |
| 79 } | |
| 80 | |
| 81 | |
| 82 class ClosureArgumentMismatchException implements Exception { | |
| 83 const ClosureArgumentMismatchException(); | |
| 84 String toString() => "Closure argument mismatch"; | |
| 85 } | |
| 86 | |
| 87 | |
| 88 class ObjectNotClosureException implements Exception { | |
| 89 const ObjectNotClosureException(); | |
| 90 String toString() => "Object is not closure"; | |
| 91 } | |
| 92 | |
| 93 | |
| 94 class IllegalArgumentException implements Exception { | |
| 95 const IllegalArgumentException([arg = ""]) : _arg = arg; | |
| 96 String toString() => "Illegal argument(s): $_arg"; | |
| 97 final _arg; | |
| 98 } | |
| 99 | |
| 100 | |
| 101 class OutOfMemoryException implements Exception { | |
| 102 const OutOfMemoryException(); | |
| 103 String toString() => "Out of Memory"; | |
| 104 } | |
| 105 | |
| 106 | |
| 107 class StackOverflowException implements Exception { | |
| 108 const StackOverflowException(); | |
| 109 String toString() => "Stack Overflow"; | |
| 110 } | |
| 111 | |
| 112 | |
| 113 /** | |
| 114 * Exception thrown when a string or some other data does not have an expected | |
| 115 * format and cannot be parsed or processed. | |
| 116 */ | |
| 117 class FormatException implements Exception { | |
| 118 /** | |
| 119 * A message describing the format error. | |
| 120 */ | |
| 121 final String message; | |
| 122 | |
| 123 /** | |
| 124 * Creates a new FormatException with an optional error [message]. | |
| 125 */ | |
| 126 const FormatException([this.message = ""]); | |
| 127 | |
| 128 String toString() => "FormatException: $message"; | |
| 129 } | |
| 130 | |
| 131 | |
| 132 class WrongArgumentCountException implements Exception { | |
| 133 const WrongArgumentCountException(); | |
| 134 String toString() => "WrongArgumentCountException"; | |
| 135 } | |
| 136 | |
| 137 | |
| 138 class NullPointerException implements Exception { | |
| 139 const NullPointerException([this.functionName, this.arguments = const []]); | |
| 140 String toString() { | |
| 141 if (functionName == null) { | |
| 142 return exceptionName; | |
| 143 } else { | |
| 144 return "$exceptionName : method: '$functionName'\n" | |
| 145 "Receiver: null\n" | |
| 146 "Arguments: $arguments"; | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 String get exceptionName() => "NullPointerException"; | |
| 151 | |
| 152 final String functionName; | |
| 153 final List arguments; | |
| 154 } | |
| 155 | |
| 156 | |
| 157 class NoMoreElementsException implements Exception { | |
| 158 const NoMoreElementsException(); | |
| 159 String toString() => "NoMoreElementsException"; | |
| 160 } | |
| 161 | |
| 162 | |
| 163 class EmptyQueueException implements Exception { | |
| 164 const EmptyQueueException(); | |
| 165 String toString() => "EmptyQueueException"; | |
| 166 } | |
| 167 | |
| 168 | |
| 169 class UnsupportedOperationException implements Exception { | |
| 170 const UnsupportedOperationException(String this._message); | |
| 171 String toString() => "UnsupportedOperationException: $_message"; | |
| 172 final String _message; | |
| 173 } | |
| 174 | |
| 175 | |
| 176 class NotImplementedException implements Exception { | |
| 177 const NotImplementedException([String message]) : this._message = message; | |
| 178 String toString() => (this._message !== null | |
| 179 ? "NotImplementedException: $_message" | |
| 180 : "NotImplementedException"); | |
| 181 final String _message; | |
| 182 } | |
| 183 | |
| 184 | |
| 185 class IllegalJSRegExpException implements Exception { | |
| 186 const IllegalJSRegExpException(String this._pattern, String this._errmsg); | |
| 187 String toString() => "IllegalJSRegExpException: '$_pattern' '$_errmsg'"; | |
| 188 final String _pattern; | |
| 189 final String _errmsg; | |
| 190 } | |
| 191 | |
| 192 | |
| 193 class IntegerDivisionByZeroException implements Exception { | |
| 194 const IntegerDivisionByZeroException(); | |
| 195 String toString() => "IntegerDivisionByZeroException"; | |
| 196 } | |
| 197 | |
| 198 /** | |
| 199 * Exception thrown when a runtime error occurs. | |
| 200 */ | |
| 201 class RuntimeError implements Exception { | |
| 202 final message; | |
| 203 RuntimeError(this.message); | |
| 204 String toString() => "RuntimeError: $message"; | |
| 205 } | |
| OLD | NEW |