From a62c570205aeafa4f9043469e40f8f125c091d35 Mon Sep 17 00:00:00 2001
From: Him188 <Him188@mamoe.net>
Date: Sun, 9 May 2021 01:24:31 +0800
Subject: [PATCH] Add ExceptionCollector.throwLast

---
 mirai-core-utils/src/commonMain/kotlin/ExceptionCollector.kt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mirai-core-utils/src/commonMain/kotlin/ExceptionCollector.kt b/mirai-core-utils/src/commonMain/kotlin/ExceptionCollector.kt
index 02ca56ca6..8b4522c08 100644
--- a/mirai-core-utils/src/commonMain/kotlin/ExceptionCollector.kt
+++ b/mirai-core-utils/src/commonMain/kotlin/ExceptionCollector.kt
@@ -64,6 +64,11 @@ public class ExceptionCollector : Sequence<Throwable> {
         throw getLast()!!
     }
 
+    @TerminalOperation
+    public fun throwLast(): Nothing {
+        throw getLast() ?: error("Internal error: expected at least one exception collected.")
+    }
+
     @DslMarker
     private annotation class TerminalOperation