Use AssertionError rather than Exceptions for unexpected behaviour in io.

Follow up to https://dart-review.googlesource.com/c/sdk/+/257140/comments/38b33a34_5c1914ff.

Unreachable code in error handling.

Change-Id: I9e8a5b19372d63a604efcdf9856a618e5f7b520f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/258513
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
This commit is contained in:
Kallen Tu 2022-09-19 16:42:30 +00:00 committed by Commit Bot
parent c76c37c254
commit a3764263d8
4 changed files with 9 additions and 9 deletions

View file

@ -1549,23 +1549,23 @@ class _NativeSocket extends _NativeSocketNativeWrapper with _ServiceObject {
static createError(error, String message,
[InternetAddress? address, int? port]) {
if (error is OSError) {
return new SocketException(message,
return SocketException(message,
osError: error, address: address, port: port);
} else if (error is List) {
assert(isErrorResponse(error));
switch (error[0]) {
case _illegalArgumentResponse:
return new ArgumentError();
return ArgumentError();
case _osErrorResponse:
return new SocketException(message,
osError: new OSError(error[2], error[1]),
return SocketException(message,
osError: OSError(error[2], error[1]),
address: address,
port: port);
default:
return new Exception("Unknown error");
return AssertionError("Unknown error");
}
} else {
return new SocketException(message, address: address, port: port);
return SocketException(message, address: address, port: port);
}
}

View file

@ -28,7 +28,7 @@ void _checkForErrorResponse(Object? response, String message, String path) {
case _fileClosedResponse:
throw FileSystemException("File closed", path);
default:
throw Exception("Unknown error");
throw AssertionError("Unknown error");
}
}
}

View file

@ -255,7 +255,7 @@ class _Directory extends FileSystemEntity implements Directory {
response[_osErrorResponseErrorCode] as int);
throw FileSystemException(message, path, err);
default:
throw Exception("Unknown error");
throw AssertionError("Unknown error");
}
}
}

View file

@ -266,7 +266,7 @@ class _Link extends FileSystemEntity implements Link {
response[_osErrorResponseErrorCode] as int);
throw FileSystemException(message, path, err);
default:
throw Exception("Unknown error");
throw AssertionError("Unknown error");
}
}
}