+exception registration sugar

This commit is contained in:
Sergey Chernov 2022-09-08 14:49:03 +03:00
parent 39aa031bf0
commit da1289e3be

View File

@ -34,9 +34,10 @@ open class ExceptionsRegistry {
* Register an exception with a code with a handler that creates its instance. Note that the
* handler _should not throw anything_ but rather create an instance of the exception.
*/
inline fun <reified T : Throwable> register(code: String, noinline block: (message: String?) -> T) {
handlers[code] = block
classCodes[T::class] = code
inline fun <reified T : Throwable> register(code: String?=null, noinline block: (message: String?) -> T) {
val _code = code ?: T::class.simpleName!!
handlers[_code] = block
classCodes[T::class] = _code
}
/**