withGet

As expected the exception is re-thrown when calling get on the CompletableFuture that had exception thrown.

GT-Sandbox-Snapshot

Code

package com.glassthought.sandbox

import gt.sandbox.util.output.Out
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import java.util.*
import java.util.concurrent.CompletableFuture

val out = Out.standard()

fun main() = runBlocking {
  val future = CompletableFuture.supplyAsync {

    throw RuntimeException("original-exc-msg-from-supplyAsync-future-block")
    "Jon Snow"
  }

  try {
    future.get()
  } catch (e: Exception) {
    out.println("Caught exception: ${e.message}")
  }

  println("")
}

Command to reproduce:

gt.sandbox.checkout.commit 0daaef350f0970bcddb7 \
&& cd "${GT_SANDBOX_REPO}" \
&& cmd.run.announce "./gradlew run --quiet"

Recorded output of command:

[2024-11-22T06:16:43.526687Z][elapsed-since-start:   41ms][tname:main/tid:1] Caught exception: java.lang.RuntimeException: original-exc-msg-from-supplyAsync-future-block

Backlinks