Have tryTest{} work with throwables

Test: NetworkStaticLibTests
Change-Id: I9ee52e7d34866c82e169bbecbca3f928bfd79993
This commit is contained in:
Chalard Jean
2021-11-24 17:34:53 +09:00
parent 2918ada958
commit 28348e43ae

View File

@@ -84,7 +84,7 @@ inline class TryExpr<T>(val result: Result<T>) {
inline infix fun cleanup(block: () -> Unit): T { inline infix fun cleanup(block: () -> Unit): T {
try { try {
block() block()
} catch (e: Exception) { } catch (e: Throwable) {
val originalException = result.exceptionOrNull() val originalException = result.exceptionOrNull()
if (null == originalException) { if (null == originalException) {
throw e throw e
@@ -101,7 +101,7 @@ inline class TryExpr<T>(val result: Result<T>) {
fun <T> tryTest(block: () -> T) = TryExpr( fun <T> tryTest(block: () -> T) = TryExpr(
try { try {
Result.success(block()) Result.success(block())
} catch (e: Exception) { } catch (e: Throwable) {
Result.failure(e) Result.failure(e)
}) })