Outcome School’s Post

Kotlin Interview Question: What happens if an exception is thrown inside an async coroutine, but await() is never called? Answer: Unlike launch, which throws exceptions right away, async holds exceptions in its Deferred result. If you don’t call await(), the exception will go unnoticed. • async returns a Deferred, which captures the exception and only throws it when you call await(). • If await() is never called, the exception sits silently in the Deferred and is effectively ignored. val deferred = async { throw RuntimeException("Something went wrong") } // No await() here, so the exception is never seen. #Kotlin #AndroidDev

AMIT SHEKHAR

Founder @ Outcome School | Coder | Teacher | Mentor | Open Source | IIT 2010-14 | Android | Machine Learning | Backend

6d

#AndroidDev #Kotlin

Like
Reply

To view or add a comment, sign in

Explore content categories