I’ve just created such a monster: ``` private ...
# announcements
p
I’ve just created such a monster:
Copy code
private fun <T> tryWithExceptionMapping(operation: () -> T,
                                            vararg mappings: Pair<KClass<out Throwable>, () -> Throwable>): T {
        return try {
            operation.invoke()
        } catch (throwableToMap: Throwable) {
            val matchingMapping = mappings
                    .filter { it.first.java.isInstance(throwableToMap) }
                    .firstOrNull()
                    ?: Pair(Throwable::class, { throw throwableToMap })
            val mappedThrowable = matchingMapping.second.invoke()
            throw mappedThrowable
        }
    }