From da1289e3be10de41b85fe2035d3b996d24199563 Mon Sep 17 00:00:00 2001 From: sergeych Date: Thu, 8 Sep 2022 14:49:03 +0300 Subject: [PATCH] +exception registration sugar --- .../kotlin/net.sergeych.parsec3/ExceptionsRegistry.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commonMain/kotlin/net.sergeych.parsec3/ExceptionsRegistry.kt b/src/commonMain/kotlin/net.sergeych.parsec3/ExceptionsRegistry.kt index 037ab62..7fe7932 100644 --- a/src/commonMain/kotlin/net.sergeych.parsec3/ExceptionsRegistry.kt +++ b/src/commonMain/kotlin/net.sergeych.parsec3/ExceptionsRegistry.kt @@ -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 register(code: String, noinline block: (message: String?) -> T) { - handlers[code] = block - classCodes[T::class] = code + inline fun register(code: String?=null, noinline block: (message: String?) -> T) { + val _code = code ?: T::class.simpleName!! + handlers[_code] = block + classCodes[T::class] = _code } /**