resumeWithException

Resumes the execution of the corresponding coroutine so that the exception is re-thrown right after the last suspension point.

inline fun <T> Continuation<T>.resumeWithException(exception: Throwable)(source)
import kotlinx.coroutines.*
import kotlin.coroutines.*

suspend fun fail(): Int = suspendCancellableCoroutine { cont ->
    // Resume the coroutine with an exception
    cont.resumeWithException(RuntimeException("Something went wrong"))
}

fun main() = runBlocking {
    try {
        fail()
    } catch (e: Throwable) {
        println("Caught exception: ${e.message}")
    }
}

Source