All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.github.insanusmokrassar.TelegramBotAPI.utils.HandleSafely.kt Maven / Gradle / Ivy

There is a newer version: 0.28.3
Show newest version
package com.github.insanusmokrassar.TelegramBotAPI.utils

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.supervisorScope

/**
 * It will run [block] inside of [supervisorScope] to avoid problems with catching of exceptions
 *
 * @param [onException] Will be called when happen exception inside of [block]. By default will throw exception - this
 * exception will be available for catching
 */
suspend inline fun  handleSafely(
    noinline onException: suspend (Exception) -> T = { throw it },
    noinline block: suspend CoroutineScope.() -> T
): T {
    return try {
        supervisorScope(block)
    } catch (e: Exception) {
        onException(e)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy