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