I have two functions that invoke a code block with a try-catch like:
fun <R: Any> executeRestCall(
block: () -> R
): R {
try {
return block()
} catch (ex: RestClientException) {
throw IllegalArgumentException(ex.message)
}
}
fun <R: Any> executeProcessCall(
block: () -> R
): R {
try {
return block()
} catch (ex: RuntimeException) {
throw IllegalStateException(ex.message)
}
}
I need to parametrize required exception. How can this function be refactored?