1
我使用'Retrofit'进行http转移。改造:自定义ErrorHandler,UndeclaredThrowableException
我做了一个自定义ErrorHandler
像下面的代码。
public class CustomErrorHandler implements ErrorHandler {
@Override
public Throwable handleError(RetrofitError cause) {
if (RetrofitError.Kind.NETWORK == cause.getKind()) {
Throwable throwable = cause.getCause();
if (throwable instanceof SocketTimeoutException)
return throwable;
else if (throwable instanceof ConnectException)
return throwable;
}
return cause;
}
}
当我尝试调试,throwable
是在CustomErrorHandler.handleError()
SocketTimeoutException
或ConnectException
实例。
但是,下面的提示UndeclaredThrowableException
。
private SignOutSuccessResponse trySignOut(String email, String userToken) throws Exception {
RestAdapter.Builder builder = new RestAdapter.Builder();
builder.setEndpoint(ServerInfo.END_POINT_API);
builder.setErrorHandler(new CustomErrorHandler());
if (BuildConfig.DEBUG)
builder.setLogLevel(RestAdapter.LogLevel.FULL);
API sessionAPI = builder.build().create(API.class);
return sessionAPI.signOut(email, userToken);
}
如何解决此问题而不是this way?
我使用
- 的Android工作室
- 改造1.7.1
- OkHttp 2.0.0
请帮我ㅠㅠ
哦,我不知道'SocketTimeException'和'ConnectException'是'checked exception'。谢谢! – 2014-10-27 13:38:45