| 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 class Error { | 7 class Error { |
| 8 const Error(); | 8 const Error(); |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 * method with the same name on the receiver, if available. This is | 144 * method with the same name on the receiver, if available. This is |
| 145 * the method that would have been called if the parameters had matched. | 145 * the method that would have been called if the parameters had matched. |
| 146 */ | 146 */ |
| 147 const NoSuchMethodError(Object this._receiver, | 147 const NoSuchMethodError(Object this._receiver, |
| 148 String this._memberName, | 148 String this._memberName, |
| 149 List this._arguments, | 149 List this._arguments, |
| 150 Map<String,dynamic> this._namedArguments, | 150 Map<String,dynamic> this._namedArguments, |
| 151 [List existingArgumentNames = null]) | 151 [List existingArgumentNames = null]) |
| 152 : this._existingArgumentNames = existingArgumentNames; | 152 : this._existingArgumentNames = existingArgumentNames; |
| 153 | 153 |
| 154 String toString() { | 154 external String toString(); |
| 155 StringBuffer sb = new StringBuffer(); | |
| 156 int i = 0; | |
| 157 if (_arguments != null) { | |
| 158 for (; i < _arguments.length; i++) { | |
| 159 if (i > 0) { | |
| 160 sb.add(", "); | |
| 161 } | |
| 162 sb.add(Error.safeToString(_arguments[i])); | |
| 163 } | |
| 164 } | |
| 165 if (_namedArguments != null) { | |
| 166 _namedArguments.forEach((String key, var value) { | |
| 167 if (i > 0) { | |
| 168 sb.add(", "); | |
| 169 } | |
| 170 sb.add(key); | |
| 171 sb.add(": "); | |
| 172 sb.add(Error.safeToString(value)); | |
| 173 i++; | |
| 174 }); | |
| 175 } | |
| 176 if (_existingArgumentNames == null) { | |
| 177 return "NoSuchMethodError : method not found: '$_memberName'\n" | |
| 178 "Receiver: ${Error.safeToString(_receiver)}\n" | |
| 179 "Arguments: [$sb]"; | |
| 180 } else { | |
| 181 String actualParameters = sb.toString(); | |
| 182 sb = new StringBuffer(); | |
| 183 for (int i = 0; i < _existingArgumentNames.length; i++) { | |
| 184 if (i > 0) { | |
| 185 sb.add(", "); | |
| 186 } | |
| 187 sb.add(_existingArgumentNames[i]); | |
| 188 } | |
| 189 String formalParameters = sb.toString(); | |
| 190 return "NoSuchMethodError: incorrect number of arguments passed to " | |
| 191 "method named '$_memberName'\n" | |
| 192 "Receiver: ${Error.safeToString(_receiver)}\n" | |
| 193 "Tried calling: $_memberName($actualParameters)\n" | |
| 194 "Found: $_memberName($formalParameters)"; | |
| 195 } | |
| 196 } | |
| 197 } | 155 } |
| 198 | 156 |
| 199 | 157 |
| 200 /** | 158 /** |
| 201 * The operation was not allowed by the object. | 159 * The operation was not allowed by the object. |
| 202 * | 160 * |
| 203 * This [Error] is thrown when an instance cannot implement one of the methods | 161 * This [Error] is thrown when an instance cannot implement one of the methods |
| 204 * in its signature. | 162 * in its signature. |
| 205 */ | 163 */ |
| 206 class UnsupportedError implements Error { | 164 class UnsupportedError implements Error { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 234 } |
| 277 | 235 |
| 278 /** | 236 /** |
| 279 * Error thrown when a runtime error occurs. | 237 * Error thrown when a runtime error occurs. |
| 280 */ | 238 */ |
| 281 class RuntimeError implements Error { | 239 class RuntimeError implements Error { |
| 282 final message; | 240 final message; |
| 283 RuntimeError(this.message); | 241 RuntimeError(this.message); |
| 284 String toString() => "RuntimeError: $message"; | 242 String toString() => "RuntimeError: $message"; |
| 285 } | 243 } |
| OLD | NEW |