blob: 6894ac00a5f9a10dde7d30fef47a02ec6d18e8e9 [file] [log] [blame]
Roman Elizarovf29203c2018-01-11 12:39:36 +03001/*
2 * Copyright 2016-2017 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package kotlinx.coroutines.experimental
18
19/**
20 * This exception gets thrown if an exception is caught while processing [CompletionHandler] invocation for [Job].
21 */
22public actual class CompletionHandlerException public actual constructor(
23 message: String,
24 public override val cause: Throwable
25) : RuntimeException(message.withCause(cause))
26
Roman Elizarovaa461cf2018-04-11 13:20:29 +030027/**
28 * Thrown by cancellable suspending functions if the [Job] of the coroutine is cancelled while it is suspending.
29 * It indicates _normal_ cancellation of a coroutine.
30 * **It is not printed to console/log by default uncaught exception handler**.
31 * (see [handleCoroutineException]).
32 */
Vsevolod Tolstopyatov96191342018-04-20 18:13:33 +030033public actual open class CancellationException actual constructor(message: String?) : IllegalStateException(message)
Roman Elizarovf29203c2018-01-11 12:39:36 +030034
35/**
36 * Thrown by cancellable suspending functions if the [Job] of the coroutine is cancelled or completed
37 * without cause, or with a cause or exception that is not [CancellationException]
38 * (see [Job.getCancellationException]).
39 */
40public actual class JobCancellationException public actual constructor(
41 message: String,
42 public override val cause: Throwable?,
43 /**
44 * The job that was cancelled.
45 */
46 public actual val job: Job
47) : CancellationException(message.withCause(cause)) {
48 override fun toString(): String = "${super.toString()}; job=$job"
49 override fun equals(other: Any?): Boolean =
50 other === this ||
51 other is JobCancellationException && other.message == message && other.job == job && other.cause == cause
52 override fun hashCode(): Int =
53 (message!!.hashCode() * 31 + job.hashCode()) * 31 + (cause?.hashCode() ?: 0)
54}
55
Roman Elizarovf29203c2018-01-11 12:39:36 +030056internal actual class DispatchException actual constructor(message: String, cause: Throwable) : RuntimeException(message.withCause(cause))
57
58@Suppress("FunctionName")
59internal fun IllegalStateException(message: String, cause: Throwable?) =
60 IllegalStateException(message.withCause(cause))
61
62private fun String.withCause(cause: Throwable?) =
63 if (cause == null) this else "$this; caused by $cause"
Roman Elizarovaa461cf2018-04-11 13:20:29 +030064
65@Suppress("NOTHING_TO_INLINE")
66internal actual inline fun Throwable.addSuppressedThrowable(other: Throwable) { /* empty */ }