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 | import java.util.concurrent.* |
| 20 | |
| 21 | /** |
| 22 | * This exception gets thrown if an exception is caught while processing [CompletionHandler] invocation for [Job]. |
| 23 | */ |
| 24 | public actual class CompletionHandlerException actual constructor( |
| 25 | message: String, |
| 26 | cause: Throwable |
| 27 | ) : RuntimeException(message, cause) |
| 28 | |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 29 | /** |
| 30 | * Thrown by cancellable suspending functions if the [Job] of the coroutine is cancelled while it is suspending. |
| 31 | * It indicates _normal_ cancellation of a coroutine. |
| 32 | * **It is not printed to console/log by default uncaught exception handler**. |
| 33 | * (see [handleCoroutineException]). |
| 34 | */ |
Roman Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 35 | public actual typealias CancellationException = java.util.concurrent.CancellationException |
| 36 | |
| 37 | /** |
| 38 | * Thrown by cancellable suspending functions if the [Job] of the coroutine is cancelled or completed |
| 39 | * without cause, or with a cause or exception that is not [CancellationException] |
| 40 | * (see [Job.getCancellationException]). |
| 41 | */ |
| 42 | public actual class JobCancellationException public actual constructor( |
| 43 | message: String, |
| 44 | cause: Throwable?, |
| 45 | /** |
| 46 | * The job that was cancelled. |
| 47 | */ |
| 48 | public actual val job: Job |
| 49 | ) : CancellationException(message) { |
| 50 | init { if (cause != null) initCause(cause) } |
| 51 | override fun toString(): String = "${super.toString()}; job=$job" |
| 52 | override fun equals(other: Any?): Boolean = |
| 53 | other === this || |
| 54 | other is JobCancellationException && other.message == message && other.job == job && other.cause == cause |
| 55 | override fun hashCode(): Int = |
| 56 | (message!!.hashCode() * 31 + job.hashCode()) * 31 + (cause?.hashCode() ?: 0) |
| 57 | } |
| 58 | |
Roman Elizarov | f29203c | 2018-01-11 12:39:36 +0300 | [diff] [blame] | 59 | internal actual class DispatchException actual constructor(message: String, cause: Throwable) : RuntimeException(message, cause) |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 60 | |
| 61 | @Suppress("NOTHING_TO_INLINE") |
| 62 | internal actual inline fun Throwable.addSuppressedThrowable(other: Throwable) = |
| 63 | addSuppressed(other) |