本文整理匯總了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);
}
}
}