Handle exceptions in after

This commit is contained in:
Eric Anderson 2018-08-17 15:09:36 -07:00
parent 778804f4c5
commit f8d30afb20
1 changed files with 15 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue;
import io.grpc.ManagedChannel; import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder; import io.grpc.ManagedChannelBuilder;
import io.grpc.internal.MoreThrowables;
import io.grpc.okhttp.OkHttpChannelBuilder; import io.grpc.okhttp.OkHttpChannelBuilder;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -181,8 +182,21 @@ public final class OkHttpClientInteropServlet extends HttpServlet {
return new AutoCloseable() { return new AutoCloseable() {
@Override @Override
public void close() throws Exception { public void close() throws Exception {
Throwable failure = null;
for (Method method : methods) { for (Method method : methods) {
method.invoke(o); try {
method.invoke(o);
} catch (Throwable t) {
if (failure == null) {
failure = t;
} else {
failure.addSuppressed(t);
}
}
}
if (failure != null) {
MoreThrowables.throwIfUnchecked(failure);
throw new Exception(failure);
} }
} }
}; };