| 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 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Exception thrown because of non-existing receiver's method. | 35 * Exception thrown because of non-existing receiver's method. |
| 36 */ | 36 */ |
| 37 class NoSuchMethodException implements Exception { | 37 class NoSuchMethodException implements Exception { |
| 38 const NoSuchMethodException(Object this._receiver, | 38 const NoSuchMethodException(Object this._receiver, |
| 39 String this._functionName, | 39 String this._functionName, |
| 40 List this._arguments, | 40 List this._arguments, |
| 41 [String this._extraMessage = ""]); | 41 [List this._existingArgumentNames = null]); |
| 42 | 42 |
| 43 String toString() { | 43 String toString() { |
| 44 StringBuffer sb = new StringBuffer(); | 44 StringBuffer sb = new StringBuffer(); |
| 45 for (int i = 0; i < _arguments.length; i++) { | 45 for (int i = 0; i < _arguments.length; i++) { |
| 46 if (i > 0) { | 46 if (i > 0) { |
| 47 sb.add(", "); | 47 sb.add(", "); |
| 48 } | 48 } |
| 49 sb.add(_arguments[i]); | 49 sb.add(_arguments[i]); |
| 50 } | 50 } |
| 51 sb.add("]"); | 51 if (_existingArgumentNames === null) { |
| 52 var x = _extraMessage; | 52 return "NoSuchMethodException : method not found: '$_functionName'\n" + |
| 53 return "NoSuchMethodException - receiver: '$_receiver' " + | 53 "Receiver: $_receiver\n" + "Arguments: [$sb]"; |
| 54 "function name: '$_functionName' arguments: [$sb]$x"; | 54 } else { |
| 55 String actualParameters = sb.toString(); |
| 56 sb = new StringBuffer(); |
| 57 for (int i = 0; i < _existingArgumentNames.length; i++) { |
| 58 if (i > 0) { |
| 59 sb.add(", "); |
| 60 } |
| 61 sb.add(_existingArgumentNames[i]); |
| 62 } |
| 63 String formalParameters = sb.toString(); |
| 64 return "NoSuchMethodException: incorrect number of arguments passed to " + |
| 65 "method named '$_functionName'\nReceiver: $_receiver\n" + |
| 66 "Tried calling: $_functionName($actualParameters)\n" + |
| 67 "Found: $_functionName($formalParameters)"; |
| 68 } |
| 55 } | 69 } |
| 56 | 70 |
| 57 final Object _receiver; | 71 final Object _receiver; |
| 58 final String _functionName; | 72 final String _functionName; |
| 59 final List _arguments; | 73 final List _arguments; |
| 60 final String _extraMessage; | 74 final List _existingArgumentNames; |
| 61 } | 75 } |
| 62 | 76 |
| 63 | 77 |
| 64 class ClosureArgumentMismatchException implements Exception { | 78 class ClosureArgumentMismatchException implements Exception { |
| 65 const ClosureArgumentMismatchException(); | 79 const ClosureArgumentMismatchException(); |
| 66 String toString() => "Closure argument mismatch"; | 80 String toString() => "Closure argument mismatch"; |
| 67 } | 81 } |
| 68 | 82 |
| 69 | 83 |
| 70 class ObjectNotClosureException implements Exception { | 84 class ObjectNotClosureException implements Exception { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 String toString() => "IllegalJSRegExpException: '$_pattern' '$_errmsg'"; | 155 String toString() => "IllegalJSRegExpException: '$_pattern' '$_errmsg'"; |
| 142 final String _pattern; | 156 final String _pattern; |
| 143 final String _errmsg; | 157 final String _errmsg; |
| 144 } | 158 } |
| 145 | 159 |
| 146 | 160 |
| 147 class IntegerDivisionByZeroException implements Exception { | 161 class IntegerDivisionByZeroException implements Exception { |
| 148 const IntegerDivisionByZeroException(); | 162 const IntegerDivisionByZeroException(); |
| 149 String toString() => "IntegerDivisionByZeroException"; | 163 String toString() => "IntegerDivisionByZeroException"; |
| 150 } | 164 } |
| OLD | NEW |