@@ -65,7 +65,7 @@ internal actual suspend inline fun recoverAndThrow(exception: Throwable): Nothin
6565 if (recoveryDisabled(exception)) throw exception
6666 suspendCoroutineUninterceptedOrReturn<Nothing > {
6767 if (it !is CoroutineStackFrame ) throw exception
68- throw recoverFromStackFrame(exception, it)
68+ throw recoverFromStackFrame(exception, it)
6969 }
7070}
7171
@@ -86,34 +86,7 @@ internal actual fun <E : Throwable> unwrap(exception: E): E {
8686private fun <E : Throwable > recoveryDisabled (exception : E ) =
8787 ! RECOVER_STACKTRACE || ! DEBUG || exception is CancellationException || exception is NonRecoverableThrowable
8888
89- @Suppress(" UNCHECKED_CAST" )
90- private fun <E : Throwable > tryCopyException (exception : E ): E ? {
91- /*
92- * Try to reflectively find constructor(), constructor(message, cause) or constructor(cause).
93- * Exceptions are shared among coroutines, so we should copy exception before recovering current stacktrace.
94- */
95- var newException: E ? = null
96- try {
97- val constructors = exception.javaClass.constructors.sortedByDescending { it.parameterTypes.size }
98- for (constructor in constructors) {
99- val parameters = constructor .parameterTypes
100- if (parameters.size == 2 && parameters[0 ] == String ::class .java && parameters[1 ] == Throwable ::class .java) {
101- newException = constructor .newInstance(exception.message, exception) as E
102- } else if (parameters.size == 1 && parameters[0 ] == Throwable ::class .java) {
103- newException = constructor .newInstance(exception) as E
104- } else if (parameters.isEmpty()) {
105- newException = (constructor .newInstance() as E ).also { it.initCause(exception) }
106- }
107-
108- if (newException != null ) {
109- break
110- }
111- }
112- } catch (e: Exception ) {
113- // Do nothing
114- }
115- return newException
116- }
89+
11790
11891private fun createStackTrace (continuation : CoroutineStackFrame ): ArrayList <StackTraceElement > {
11992 val stack = ArrayList <StackTraceElement >()
0 commit comments