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

com.loudsight.utilities.ExceptionHelper.kt Maven / Gradle / Ivy

The newest version!
package com.loudsight.utilities

object ExceptionHelper {

    fun  wrap(checkedFunction: (T) -> R): (T) -> R {
        return { t ->
            try {
                checkedFunction.invoke(t)
            } catch (e1: Exception) {
                throw e1
            }
        }
    }

    fun  wrap(checkedFunction: () -> R): () -> R {
        return {
            try {
                checkedFunction.invoke()
            } catch (e1: Exception) {
                throw e1
            }
        }
    }
//    interface FunctionX {
//       // @Throws(E::class)
//        fun apply(t: T): R
//    }
//
//    fun  wrap(checkedFunction: FunctionX ): (T) -> R {
//        return {
//            t ->
//        try {
//                checkedFunction.apply(t)
//            } catch (e1: Exception) {
//                uncheckedRethow(e1)
//            }
//            throw RuntimeException("WTF, this should not be possible");
//        }
//    }
//
    //@Throws(RuntimeException::class)
    fun  uncheckedRethow(e: Exception) {
        throw e as E
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy