Files
sdk/runtime/lib/error.dart
T
regis@google.com 47724a8491 Add support for malformed types and postpone some related errors from compile
time to execution time.

Still to do (once spec is clarified):
- properly handle generic type bounds errors
- properly handle 'instance of' type checks involving malformed types
- fix bad tests
Review URL: https://chromiumcodereview.appspot.com//9515011

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4732 260f80e4-7a28-3924-810f-c04153c831b5
2012-02-29 02:14:18 +00:00

84 lines
2.6 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Errors are created and thrown by DartVM only.
// Changes here should also be reflected in corelib/error.dart as well
class AssertionError {
factory AssertionError._uninstantiable() {
throw const UnsupportedOperationException(
"AssertionError can only be allocated by the VM");
}
static _throwNew(int assertionStart, int assertionEnd)
native "AssertionError_throwNew";
String toString() {
return "'$url': Failed assertion: line $line pos $column: " +
"'$failedAssertion' is not true.";
}
final String failedAssertion;
final String url;
final int line;
final int column;
}
class TypeError extends AssertionError {
factory TypeError._uninstantiable() {
throw const UnsupportedOperationException(
"TypeError can only be allocated by the VM");
}
static _throwNew(int location,
Object src_value,
String dst_type_name,
String dst_name,
String malformed_error)
native "TypeError_throwNew";
String toString() {
if (malformedError != null) {
return malformedError;
}
return "'$url': Failed type check: line $line pos $column: " +
"type '$srcType' is not assignable to type '$dstType' of '$dstName'.";
}
final String srcType;
final String dstType;
final String dstName;
final String malformedError;
}
class FallThroughError {
factory FallThroughError._uninstantiable() {
throw const UnsupportedOperationException(
"FallThroughError can only be allocated by the VM");
}
static _throwNew(int case_clause_pos) native "FallThroughError_throwNew";
String toString() {
return "'$url': Switch case fall-through at line $line.";
}
final String url;
final int line;
}
class InternalError {
const InternalError(this._msg);
String toString() => "InternalError: '${_msg}'";
final String _msg;
}
class StaticResolutionException implements Exception {
factory StaticResolutionException._uninstantiable() {
throw const UnsupportedOperationException(
"StaticResolutionException can only be allocated by the VM");
}
String toString() => "Unresolved static method: url '$url' line $line " +
"pos $column\n$failedResolutionLine\n";
static _throwNew(int token_pos) native "StaticResolutionException_throwNew";
final String failedResolutionLine;
final String url;
final int line;
final int column;
}