Roman Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package kotlinx.coroutines.experimental |
| 18 | |
| 19 | /** |
| 20 | * This exception gets thrown if an exception is caught while processing [CompletionHandler] invocation for [Job]. |
| 21 | */ |
| 22 | public actual class CompletionHandlerException public actual constructor( |
| 23 | message: String, |
| 24 | public override val cause: Throwable |
| 25 | ) : RuntimeException(message.withCause(cause)) |
| 26 | |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 27 | /** |
| 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 Tolstopyatov | 9619134 | 2018-04-20 18:13:33 +0300 | [diff] [blame^] | 33 | public actual open class CancellationException actual constructor(message: String?) : IllegalStateException(message) |
Roman Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 34 | |
| 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 | */ |
| 40 | public 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 Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 56 | internal actual class DispatchException actual constructor(message: String, cause: Throwable) : RuntimeException(message.withCause(cause)) |
| 57 | |
| 58 | @Suppress("FunctionName") |
| 59 | internal fun IllegalStateException(message: String, cause: Throwable?) = |
| 60 | IllegalStateException(message.withCause(cause)) |
| 61 | |
| 62 | private fun String.withCause(cause: Throwable?) = |
| 63 | if (cause == null) this else "$this; caused by $cause" |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 64 | |
| 65 | @Suppress("NOTHING_TO_INLINE") |
| 66 | internal actual inline fun Throwable.addSuppressedThrowable(other: Throwable) { /* empty */ } |