本文整理汇总了Java中java.util.concurrent.CompletionException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java CompletionException.getCause方法的具体用法?Java CompletionException.getCause怎么用?Java CompletionException.getCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.CompletionException
的用法示例。
在下文中一共展示了CompletionException.getCause方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectAsync
import java.util.concurrent.CompletionException; //导入方法依赖的package包/类
private static void connectAsync(String server) throws Exception {
try {
HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.build();
HttpRequest request = HttpRequest.newBuilder(new URI(server))
.timeout(Duration.ofMillis(TIMEOUT))
.POST(fromString("body"))
.build();
HttpResponse<String> response = client.sendAsync(request, asString()).join();
System.out.println("Received unexpected reply: " + response.statusCode());
throw new RuntimeException("unexpected successful connection");
} catch (CompletionException e) {
if (e.getCause() instanceof HttpTimeoutException) {
System.out.println("expected exception: " + e.getCause());
} else {
throw new RuntimeException("Unexpected exception received: " + e.getCause(), e);
}
}
}