下面列出了怎么用com.google.android.gms.tasks.RuntimeExecutionException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Gets the result of the Task, if it has already completed.
*
* @throws IllegalStateException if the Task is not yet complete
* @throws X if the Task failed with an exception of type X
* @throws RuntimeExecutionException if the Task failed with an exception that was not of type X
*/
@NonNull
@Override
public <X extends Throwable> ResultT getResult(@NonNull Class<X> exceptionType) throws X {
if (getFinalResult() == null) {
throw new IllegalStateException();
}
if (exceptionType.isInstance(getFinalResult().getError())) {
throw exceptionType.cast(getFinalResult().getError());
}
Throwable t = getFinalResult().getError();
if (t != null) {
throw new RuntimeExecutionException(t);
}
return getFinalResult();
}
/**
* Gets the result of the Task, if it has already completed.
*
* @throws IllegalStateException if the Task is not yet complete
* @throws RuntimeExecutionException if the Task failed with an exception
*/
@NonNull
@Override
public ResultT getResult() {
if (getFinalResult() == null) {
throw new IllegalStateException();
}
Throwable t = getFinalResult().getError();
if (t != null) {
throw new RuntimeExecutionException(t);
}
return getFinalResult();
}
@Override
public TResult getResult() {
if (mSuccess) {
return mResult;
} else {
throw new RuntimeExecutionException(mException);
}
}
private static Exception unwrap(Exception e) {
if (e instanceof RuntimeExecutionException && e.getCause() instanceof Exception) {
return (Exception) e.getCause();
}
return e;
}