我有以下结构:
try {
Request.Get(url).execute() // Apache Fluent
// do some other stuff
} catch (HttpResponseException e) {
if (e.getStatusCode() != 404) {
//drop to next catch clause
}
handle404(e);
} catch (IOException e) {
handleGenericIOException(e);
}我不知道if语句中包含了什么内容。我只想说“如果异常不是404,就像这个子句从来没有捕捉到它一样”。但是简单地调用throw e就会把它从方法中抛出。有没有办法向前传递到下一个catch子句?
发布于 2018-12-10 22:56:41
我不认为你可以“放弃”到下一个catch子句,但你可以这样做:
try {
Request.Get(url).execute() // Apache Fluent
// do some other stuff
} catch (IOException e) {
if (e instanceof HttpResponseException
&& ((HttpResponseException)e).getStatusCode()== 404) {
handle404(e);
} else {
handleGenericIOException(e);
}
}因为IOException也应该捕获HttpResponseExceptions (如果它是一个org.apache.http.client.HttpResponseException)
https://stackoverflow.com/questions/53707975
复制相似问题