| 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 // Errors are created and thrown by DartVM only. | 4 // Errors are created and thrown by DartVM only. |
| 5 // Changes here should also be reflected in corelib/error.dart as well | 5 // Changes here should also be reflected in corelib/error.dart as well |
| 6 | 6 |
| 7 class AssertionErrorImplementation implements AssertionError { | 7 class AssertionErrorImplementation implements AssertionError { |
| 8 factory AssertionErrorImplementation._uninstantiable() { | 8 factory AssertionErrorImplementation._uninstantiable() { |
| 9 throw const UnsupportedOperationException( | 9 throw new UnsupportedError( |
| 10 "AssertionError can only be allocated by the VM"); | 10 "AssertionError can only be allocated by the VM"); |
| 11 } | 11 } |
| 12 static _throwNew(int assertionStart, int assertionEnd) | 12 static _throwNew(int assertionStart, int assertionEnd) |
| 13 native "AssertionError_throwNew"; | 13 native "AssertionError_throwNew"; |
| 14 String toString() { | 14 String toString() { |
| 15 return "'$url': Failed assertion: line $line pos $column: " | 15 return "'$url': Failed assertion: line $line pos $column: " |
| 16 "'$failedAssertion' is not true."; | 16 "'$failedAssertion' is not true."; |
| 17 } | 17 } |
| 18 final String failedAssertion; | 18 final String failedAssertion; |
| 19 final String url; | 19 final String url; |
| 20 final int line; | 20 final int line; |
| 21 final int column; | 21 final int column; |
| 22 } | 22 } |
| 23 | 23 |
| 24 class TypeErrorImplementation | 24 class TypeErrorImplementation |
| 25 extends AssertionErrorImplementation | 25 extends AssertionErrorImplementation |
| 26 implements TypeError { | 26 implements TypeError { |
| 27 factory TypeErrorImplementation._uninstantiable() { | 27 factory TypeErrorImplementation._uninstantiable() { |
| 28 throw const UnsupportedOperationException( | 28 throw new UnsupportedError( |
| 29 "TypeError can only be allocated by the VM"); | 29 "TypeError can only be allocated by the VM"); |
| 30 } | 30 } |
| 31 static _throwNew(int location, | 31 static _throwNew(int location, |
| 32 Object src_value, | 32 Object src_value, |
| 33 String dst_type_name, | 33 String dst_type_name, |
| 34 String dst_name, | 34 String dst_name, |
| 35 String malformed_error) | 35 String malformed_error) |
| 36 native "TypeError_throwNew"; | 36 native "TypeError_throwNew"; |
| 37 String toString() { | 37 String toString() { |
| 38 String str = (malformedError != null) ? malformedError : ""; | 38 String str = (malformedError != null) ? malformedError : ""; |
| 39 if ((dstName != null) && (dstName.length > 0)) { | 39 if ((dstName != null) && (dstName.length > 0)) { |
| 40 str = "${str}type '$srcType' is not a subtype of " | 40 str = "${str}type '$srcType' is not a subtype of " |
| 41 "type '$dstType' of '$dstName'."; | 41 "type '$dstType' of '$dstName'."; |
| 42 } else { | 42 } else { |
| 43 str = "${str}malformed type used."; | 43 str = "${str}malformed type used."; |
| 44 } | 44 } |
| 45 return str; | 45 return str; |
| 46 } | 46 } |
| 47 final String srcType; | 47 final String srcType; |
| 48 final String dstType; | 48 final String dstType; |
| 49 final String dstName; | 49 final String dstName; |
| 50 final String malformedError; | 50 final String malformedError; |
| 51 } | 51 } |
| 52 | 52 |
| 53 class CastErrorImplementation | 53 class CastErrorImplementation |
| 54 extends TypeErrorImplementation | 54 extends TypeErrorImplementation |
| 55 implements CastError { | 55 implements CastError { |
| 56 factory CastError._uninstantiable() { | 56 factory CastError._uninstantiable() { |
| 57 throw const UnsupportedOperationException( | 57 throw new UnsupportedError( |
| 58 "CastError can only be allocated by the VM"); | 58 "CastError can only be allocated by the VM"); |
| 59 } | 59 } |
| 60 // A CastError is allocated by TypeError._throwNew() when dst_name equals | 60 // A CastError is allocated by TypeError._throwNew() when dst_name equals |
| 61 // Exceptions::kCastErrorDstName. | 61 // Exceptions::kCastErrorDstName. |
| 62 String toString() { | 62 String toString() { |
| 63 String str = (malformedError != null) ? malformedError : ""; | 63 String str = (malformedError != null) ? malformedError : ""; |
| 64 if ((dstName != null) && (dstName.length > 0)) { | 64 if ((dstName != null) && (dstName.length > 0)) { |
| 65 str = "${str}type '$srcType' is not a subtype of " | 65 str = "${str}type '$srcType' is not a subtype of " |
| 66 "type '$dstType' in type cast."; | 66 "type '$dstType' in type cast."; |
| 67 } else { | 67 } else { |
| 68 str = "${str}malformed type used in type cast."; | 68 str = "${str}malformed type used in type cast."; |
| 69 } | 69 } |
| 70 return str; | 70 return str; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 class FallThroughErrorImplementation implements FallThroughError { | 74 class FallThroughErrorImplementation implements FallThroughError { |
| 75 factory FallThroughErrorImplementation._uninstantiable() { | 75 factory FallThroughErrorImplementation._uninstantiable() { |
| 76 throw const UnsupportedOperationException( | 76 throw new UnsupportedError( |
| 77 "FallThroughError can only be allocated by the VM"); | 77 "FallThroughError can only be allocated by the VM"); |
| 78 } | 78 } |
| 79 static _throwNew(int case_clause_pos) native "FallThroughError_throwNew"; | 79 static _throwNew(int case_clause_pos) native "FallThroughError_throwNew"; |
| 80 String toString() { | 80 String toString() { |
| 81 return "'$url': Switch case fall-through at line $line."; | 81 return "'$url': Switch case fall-through at line $line."; |
| 82 } | 82 } |
| 83 final String url; | 83 final String url; |
| 84 final int line; | 84 final int line; |
| 85 } | 85 } |
| 86 | 86 |
| 87 class InternalError { | 87 class InternalError { |
| 88 const InternalError(this._msg); | 88 const InternalError(this._msg); |
| 89 String toString() => "InternalError: '${_msg}'"; | 89 String toString() => "InternalError: '${_msg}'"; |
| 90 final String _msg; | 90 final String _msg; |
| 91 } | 91 } |
| 92 | 92 |
| 93 | 93 |
| 94 // TODO(regis): This class will change once mirrors are available. | 94 // TODO(regis): This class will change once mirrors are available. |
| 95 class NoSuchMethodErrorImplementation implements NoSuchMethodError { | 95 class NoSuchMethodErrorImplementation implements NoSuchMethodError { |
| 96 factory NoSuchMethodErrorImplementation._uninstantiable() { | 96 factory NoSuchMethodErrorImplementation._uninstantiable() { |
| 97 throw const UnsupportedOperationException( | 97 throw new UnsupportedError( |
| 98 "NoSuchMethodError can only be allocated by the VM"); | 98 "NoSuchMethodError can only be allocated by the VM"); |
| 99 } | 99 } |
| 100 | 100 |
| 101 String toString() => "No such method: '$functionName', url '$url' line $line " | 101 String toString() => "No such method: '$functionName', url '$url' line $line " |
| 102 "pos $column\n$failedResolutionLine\n"; | 102 "pos $column\n$failedResolutionLine\n"; |
| 103 | 103 |
| 104 static _throwNew(int call_pos, String functionName) | 104 static _throwNew(int call_pos, String functionName) |
| 105 native "NoSuchMethodError_throwNew"; | 105 native "NoSuchMethodError_throwNew"; |
| 106 | 106 |
| 107 final String functionName; | 107 final String functionName; |
| 108 final String failedResolutionLine; | 108 final String failedResolutionLine; |
| 109 final String url; | 109 final String url; |
| 110 final int line; | 110 final int line; |
| 111 final int column; | 111 final int column; |
| 112 } | 112 } |
| 113 | 113 |
| 114 | 114 |
| 115 class AbstractClassInstantiationErrorImplementation | 115 class AbstractClassInstantiationErrorImplementation |
| 116 implements AbstractClassInstantiationError { | 116 implements AbstractClassInstantiationError { |
| 117 | 117 |
| 118 factory AbstractClassInstantiationErrorImplementation._uninstantiable() { | 118 factory AbstractClassInstantiationErrorImplementation._uninstantiable() { |
| 119 throw const UnsupportedOperationException( | 119 throw new UnsupportedError( |
| 120 "AbstractClassInstantiationError can only be allocated by the VM"); | 120 "AbstractClassInstantiationError can only be allocated by the VM"); |
| 121 } | 121 } |
| 122 | 122 |
| 123 static _throwNew(int case_clause_pos, String className) | 123 static _throwNew(int case_clause_pos, String className) |
| 124 native "AbstractClassInstantiationError_throwNew"; | 124 native "AbstractClassInstantiationError_throwNew"; |
| 125 | 125 |
| 126 String toString() { | 126 String toString() { |
| 127 return "Cannot instantiate abstract class $className: " | 127 return "Cannot instantiate abstract class $className: " |
| 128 "url '$url' line $line"; | 128 "url '$url' line $line"; |
| 129 } | 129 } |
| 130 | 130 |
| 131 final String className; | 131 final String className; |
| 132 final String url; | 132 final String url; |
| 133 final int line; | 133 final int line; |
| 134 } | 134 } |
| OLD | NEW |