ResponseHandler<RedditRequestResponse> rh = new ResponseHandler<RedditRequestResponse>() {
@Override
public RedditRequestResponse handleResponse(
final HttpResponse response) throws IOException, RedditException {
int statusCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
if (entity == null) {
throw new ClientProtocolException("Response contains no content");
}
String responseBody = EntityUtils.toString(entity);
if (statusCode != HttpStatus.SC_OK) {
throw new RedditException(generateErrorString(statusCode, input, responseBody));
}
return new RedditRequestResponse(statusCode, responseBody);
}
};
我想从包含响应正文的RedditException
投出自己的handleResponse()
。但是,当我尝试(如上面的代码)时,我收到RedditException not compatible with throws clause
错误。我怀疑这与@Override有关。究竟是什么被覆盖了?包含此方法的类不会从任何其他类继承,也不会实现我能告诉的任何接口。
答案 0 :(得分:1)
如果你让RedditException
延长IOException
,那么你就可以通过保持相同的方法签名来解决这个问题