@@ -29,7 +29,7 @@ private val stackTraceRecoveryClassName = runCatching {
29
29
internal actual fun <E : Throwable > recoverStackTrace (exception : E ): E {
30
30
if (! RECOVER_STACK_TRACES ) return exception
31
31
// No unwrapping on continuation-less path: exception is not reported multiple times via slow paths
32
- val copy = tryCopyException (exception) ? : return exception
32
+ val copy = tryCopyAndVerify (exception) ? : return exception
33
33
return copy.sanitizeStackTrace()
34
34
}
35
35
@@ -66,9 +66,7 @@ private fun <E : Throwable> recoverFromStackFrame(exception: E, continuation: Co
66
66
val (cause, recoveredStacktrace) = exception.causeAndStacktrace()
67
67
68
68
// Try to create an exception of the same type and get stacktrace from continuation
69
- val newException = tryCopyException(cause) ? : return exception
70
- // Verify that the new exception has the same message as the original one (bail out if not, see #1631)
71
- if (newException.message != cause.message) return exception
69
+ val newException = tryCopyAndVerify(cause) ? : return exception
72
70
// Update stacktrace
73
71
val stacktrace = createStackTrace(continuation)
74
72
if (stacktrace.isEmpty()) return exception
@@ -80,6 +78,13 @@ private fun <E : Throwable> recoverFromStackFrame(exception: E, continuation: Co
80
78
return createFinalException(cause, newException, stacktrace)
81
79
}
82
80
81
+ private fun <E : Throwable > tryCopyAndVerify (exception : E ): E ? {
82
+ val newException = tryCopyException(exception) ? : return null
83
+ // Verify that the new exception has the same message as the original one (bail out if not, see #1631)
84
+ if (newException.message != exception.message) return null
85
+ return newException
86
+ }
87
+
83
88
/*
84
89
* Here we partially copy original exception stackTrace to make current one much prettier.
85
90
* E.g. for
0 commit comments