-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathExceptions.kt
47 lines (40 loc) · 1.92 KB
/
Exceptions.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.coroutines
import kotlinx.coroutines.internal.*
import kotlinx.coroutines.internal.SuppressSupportingThrowableImpl
/**
* Thrown by cancellable suspending functions if the [Job] of the coroutine is cancelled while it is suspending.
* It indicates _normal_ cancellation of a coroutine.
* **It is not printed to console/log by default uncaught exception handler**.
* (see [CoroutineExceptionHandler]).
*/
public actual typealias CancellationException = kotlin.coroutines.cancellation.CancellationException
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.internal.LowPriorityInOverloadResolution
public actual fun CancellationException(message: String?, cause: Throwable?): CancellationException =
CancellationException(message, cause)
/**
* Thrown by cancellable suspending functions if the [Job] of the coroutine is cancelled or completed
* without cause, or with a cause or exception that is not [CancellationException]
* (see [Job.getCancellationException]).
*/
internal actual class JobCancellationException public actual constructor(
message: String,
cause: Throwable?,
internal actual val job: Job
) : CancellationException(message, cause) {
override fun toString(): String = "${super.toString()}; job=$job"
override fun equals(other: Any?): Boolean =
other === this ||
other is JobCancellationException && other.message == message && other.job == job && other.cause == cause
override fun hashCode(): Int =
(message!!.hashCode() * 31 + job.hashCode()) * 31 + (cause?.hashCode() ?: 0)
}
@Suppress("NOTHING_TO_INLINE")
internal actual inline fun Throwable.addSuppressedThrowable(other: Throwable) {
if (this is SuppressSupportingThrowableImpl) addSuppressed(other)
}
// For use in tests
internal actual val RECOVER_STACK_TRACES: Boolean = false