1 /* 2 * Copyright 2016-2021 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 import kotlinx.coroutines.internal.* 8 import kotlinx.coroutines.internal.SuppressSupportingThrowableImpl 9 10 /** 11 * Thrown by cancellable suspending functions if the [Job] of the coroutine is cancelled while it is suspending. 12 * It indicates _normal_ cancellation of a coroutine. 13 * **It is not printed to console/log by default uncaught exception handler**. 14 * (see [CoroutineExceptionHandler]). 15 */ 16 public actual typealias CancellationException = kotlin.coroutines.cancellation.CancellationException 17 18 /** 19 * Thrown by cancellable suspending functions if the [Job] of the coroutine is cancelled or completed 20 * without cause, or with a cause or exception that is not [CancellationException] 21 * (see [Job.getCancellationException]). 22 */ 23 internal actual class JobCancellationException public actual constructor( 24 message: String, 25 cause: Throwable?, 26 internal actual val job: Job 27 ) : CancellationException(message, cause) { toStringnull28 override fun toString(): String = "${super.toString()}; job=$job" 29 override fun equals(other: Any?): Boolean = 30 other === this || 31 other is JobCancellationException && other.message == message && other.job == job && other.cause == cause 32 override fun hashCode(): Int = 33 (message!!.hashCode() * 31 + job.hashCode()) * 31 + (cause?.hashCode() ?: 0) 34 } 35 36 @Suppress("NOTHING_TO_INLINE") 37 internal actual inline fun Throwable.addSuppressedThrowable(other: Throwable) { 38 if (this is SuppressSupportingThrowableImpl) addSuppressed(other) 39 } 40 41 // For use in tests 42 internal actual val RECOVER_STACK_TRACES: Boolean = false 43