| 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 */ | 9 */ |
| 10 interface Exception default ExceptionImplementation { | 10 interface Exception default ExceptionImplementation { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Exception thrown because of attempt to modify an immutable object. | 28 * Exception thrown because of attempt to modify an immutable object. |
| 29 */ | 29 */ |
| 30 class IllegalAccessException implements Exception { | 30 class IllegalAccessException implements Exception { |
| 31 const IllegalAccessException(); | 31 const IllegalAccessException(); |
| 32 String toString() => "Attempt to modify an immutable object"; | 32 String toString() => "Attempt to modify an immutable object"; |
| 33 } | 33 } |
| 34 | 34 |
| 35 | 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 { | 36 class ClosureArgumentMismatchException implements Exception { |
| 83 const ClosureArgumentMismatchException(); | 37 const ClosureArgumentMismatchException(); |
| 84 String toString() => "Closure argument mismatch"; | 38 String toString() => "Closure argument mismatch"; |
| 85 } | 39 } |
| 86 | 40 |
| 87 | 41 |
| 88 class ObjectNotClosureException implements Exception { | 42 class ObjectNotClosureException implements Exception { |
| 89 const ObjectNotClosureException(); | 43 const ObjectNotClosureException(); |
| 90 String toString() => "Object is not closure"; | 44 String toString() => "Object is not closure"; |
| 91 } | 45 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 150 } |
| 197 | 151 |
| 198 /** | 152 /** |
| 199 * Exception thrown when a runtime error occurs. | 153 * Exception thrown when a runtime error occurs. |
| 200 */ | 154 */ |
| 201 class RuntimeError implements Exception { | 155 class RuntimeError implements Exception { |
| 202 final message; | 156 final message; |
| 203 RuntimeError(this.message); | 157 RuntimeError(this.message); |
| 204 String toString() => "RuntimeError: $message"; | 158 String toString() => "RuntimeError: $message"; |
| 205 } | 159 } |
| OLD | NEW |