safely

suspend fun <T> safely(onException: ExceptionHandler<T> = defaultSafelyExceptionHandler, block: suspend CoroutineScope.() -> T): T(source)

It will run block inside of supervisorScope to avoid problems with catching of exceptions

Priorities of ExceptionHandlers:

Remember, that ExceptionHandler from CoroutineContext.get will be used anyway if it is available. After it will be called onException

Parameters

onException

Will be called when happen exception inside of block. By default will throw exception - this exception will be available for catching

See also