Using the raise syntax, if I'm calling a function ...
# arrow
p
Using the raise syntax, if I'm calling a function that throws throwable, do I have to
catch ( { func() }) catch { raise(it) }
or is there some other function / syntax I have faield to discover
y
result { }
will turn it into a
Result
, which you can then
bind()
. Usually raising
Throwable
is unusual, though. You likely want to
catch
a specific exception, and then
raise
some domain-equivalent
👍 1
Adding to that,
Raise<Throwable>
can be somewhat legitimate when used with
withError
. Thinking about it a bit, we should probably add a
withException
or
withCatch
or something that takes a reified Throwable type and lets you map it to a raised error. I recall needing something like that before.
Copy code
inline fun <reified T: Throwable, Error, R> Raise<Error>.withCatch(transform: (T) -> Error, block: () -> R) = catch(block) { t: T -> raise(transform(t)) }