Strange Exception at read
向雅
fyaoxy at gmail.com
Thu Nov 12 06:33:24 PST 2009
I not family with other part howto wrap the os error.
Just in this case, Indeed I cannot take any action to cover it.
I checked out sun.nio.fs.WindowsException which do some exception
wrap. I think sun.nio.ch maybe need some same like thing.
My question is :
If both do wrap, so whether can unify these wrap?
WindowsException:
private IOException translateToIOException(String file, String other) {
// not created with last error
if (lastError() == 0)
return new IOException(errorString());
// handle specific cases
if (lastError() == ERROR_FILE_NOT_FOUND || lastError() ==
ERROR_PATH_NOT_FOUND)
return new NoSuchFileException(file, other, null);
if (lastError() == ERROR_FILE_EXISTS || lastError() ==
ERROR_ALREADY_EXISTS)
return new FileAlreadyExistsException(file, other, null);
if (lastError() == ERROR_ACCESS_DENIED)
return new AccessDeniedException(file, other, null);
// fallback to the more general exception
return new FileSystemException(file, other, errorString());
}
BTW, I think, for those os error not in given domain, whether wrap to
RuntimeException subclass.
in windows, WSA use some error code scopes. 5 is a windows common
error. I not think it in aio scope.
And in the callback mode, failed method already hide the exception
type. Pass a RuntimeException no any difference.
So we can tell user in API doc, failed method's exc parameter maybe
unchecked, maybe checked.
unchecked exception in the failed method indicate that some true
exception occurs.
致敬
向雅
2009/11/12 Alan Bateman <Alan.Bateman at sun.com>:
> 向雅 wrote:
>>
>> :
>> Yes,
>> for example the IOException in this message, I got a "IOException:
>> Access Denied".
>> I debug to Iocp get the os errno: 5, windows system error number.
>> I tested aio File channel, I get the errno 5 again, but it wrapped
>> with AccessDeniedException.
>> So I browsed the new file channel implementation, besides
>> AccessDeniedException,
>> there have more specific exception.
>>
>
> The "Access denied" issue that you ran into with the Windows 7 firewall is,
> in my mind anyway, obscure and probably impossible to differentiate from a
> serious implementation bug. It's also not clear to me what recovery action
> you could take that would be different to other I/O errors. The only case
> that I think we should add a specific exception for is the "reset by peer"
> case (that applies to SocketChannel and legacy Socket aswell).
>
> -Alan.
>
More information about the nio-dev
mailing list