1 /*
2 * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
5 package kotlinx.coroutines
6
7 internal expect val DEBUG: Boolean
8 internal expect val Any.hexAddress: String
9 internal expect val Any.classSimpleName: String
assertnull10 internal expect fun assert(value: () -> Boolean)
11
12 /**
13 * Throwable which can be cloned during stacktrace recovery in a class-specific way.
14 * For additional information about stacktrace recovery see [STACKTRACE_RECOVERY_PROPERTY_NAME]
15 *
16 * Example of usage:
17 * ```
18 * class BadResponseCodeException(val responseCode: Int) : Exception(), CopyableThrowable<BadResponseCodeException> {
19 *
20 * override fun createCopy(): BadResponseCodeException {
21 * val result = BadResponseCodeException(responseCode)
22 * result.initCause(this)
23 * return result
24 * }
25 * ```
26 *
27 * Copy mechanism is used only on JVM, but it might be convenient to implement it in common exceptions,
28 * so on JVM their stacktraces will be properly recovered.
29 */
30 @ExperimentalCoroutinesApi // Since 1.2.0, no ETA on stability
31 public interface CopyableThrowable<T> where T : Throwable, T : CopyableThrowable<T> {
32
33 /**
34 * Creates a copy of the current instance.
35 * For better debuggability, it is recommended to use original exception as [cause][Throwable.cause] of the resulting one.
36 * Stacktrace of copied exception will be overwritten by stacktrace recovery machinery by [Throwable.setStackTrace] call.
37 * An exception can opt-out of copying by returning `null` from this function.
38 */
39 public fun createCopy(): T?
40 }
41