Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
How does exception propagation works on CoroutineScope.async?

I see multiple sources claiming that an exception happening inside an async{} block is not delivered anywhere and only stored in the Deferred instance. The claim is that the exception remains "hidden" and only influences things outside at the moment where one will call await(). This is often described as one of the main differences between launch{} and async{}. Here is an example.

An uncaught exception inside the async code is stored inside the resulting Deferred and is not delivered anywhere else, it will get silently dropped unless processed

According to this claim, at least the way I understand it, the following code should not throw, since no-one is calling await:

// throws
runBlocking {
  async { throw Exception("Oops") }
}

And yet, the exception gets thrown. This is also discussed here, but I could not really understand why by reading this.

So it seems to me that when async throws, a "cancelation signal" is propagated on the parent scope, even if await() does not get called. Aka the exception does not really remain hidden, nor silently dropped, as the quote above states. Is my assumption correct?

Now, if we pass a SupervisorJob(), the code does not throw:

// does not throw
runBlocking {
  async(SupervisorJob()) { throw Exception("Oops") }
}

This seems reasonable since supervisor job is meant to swallow failures.

And now comes the part I do not understand at all. If we pass Job(), the code still runs without throwing, even though Job() is supposed to propagate failures to its parent scope:

// does not throw. Why?
runBlocking {
  async(Job()) { throw Exception("Oops") }
}

So my question is, why passing no Job throws, but passing either Job or SupervisorJob does not throw?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda