diff --git a/src/main/kotlin/com/github/michaelbull/result/Result.kt b/src/main/kotlin/com/github/michaelbull/result/Result.kt index 44b14af..f8d3283 100644 --- a/src/main/kotlin/com/github/michaelbull/result/Result.kt +++ b/src/main/kotlin/com/github/michaelbull/result/Result.kt @@ -11,14 +11,14 @@ sealed class Result { companion object { /** - * Invokes a [function] and wraps it in a [Result], returning an [Err] if a [Throwable] + * Invokes a [function] and wraps it in a [Result], returning an [Err] if an [Exception] * was thrown, otherwise [Ok]. */ - inline fun of(function: () -> T): Result { + inline fun of(function: () -> T): Result { return try { Ok(function.invoke()) - } catch (t: Throwable) { - Err(t) + } catch (ex: Exception) { + Err(ex) } } } diff --git a/src/test/kotlin/com/github/michaelbull/result/ResultTest.kt b/src/test/kotlin/com/github/michaelbull/result/ResultTest.kt index dcd574c..414393d 100644 --- a/src/test/kotlin/com/github/michaelbull/result/ResultTest.kt +++ b/src/test/kotlin/com/github/michaelbull/result/ResultTest.kt @@ -18,12 +18,12 @@ internal class ResultTest { @Test internal fun returnsErrIfInvocationFails() { - val throwable = IllegalArgumentException("throw me") - val callback = { throw throwable } + val exception = IllegalArgumentException("throw me") + val callback = { throw exception } val error = Result.of(callback).getError()!! assertSame( - expected = throwable, + expected = exception, actual = error ) }