Leo Laudouard
09/23/2021, 10:30 AMTimeoutCancellationException
, which is a CancellationException
.
Hence, when using Either.catch
to make a request, the exception is considered 'fatal', since 793a51edce
, and re-thrown.
My question is, why is this considered fatal ?
Thanks !simon.vergauwen
09/23/2021, 10:48 AMsimon.vergauwen
09/23/2021, 10:49 AMLeo Laudouard
09/23/2021, 12:10 PMsimon.vergauwen
09/23/2021, 12:14 PMEither.catchFatal
for such use-cases 🤔
This has been on my mind for some time, since with this style it’s not easy to capture TimeoutCancellationException
like you say.
Or Either.catchPrecise
where you can say E : TimeoutCancellationException
so you get.
val e: Either<TimeoutCancellationException, Unit> = Either.catchPrecise {
withTimeout(...) {
delay(...)
}
}
Leo Laudouard
09/23/2021, 12:23 PMLeo Laudouard
09/23/2021, 12:24 PMsimon.vergauwen
09/23/2021, 12:24 PMsimon.vergauwen
09/23/2021, 12:25 PMCancellationException
. The reason it’s thrown is so that async programs can be correctly closed using structured concurrency.
If you accidentally swallow CancellationException
then your program is prone to leaking async processes and recourcessimon.vergauwen
09/23/2021, 12:25 PMraulraja
09/23/2021, 2:14 PMcatchFatal
makes sense for those programs that want to capture all exceptions such as profilers, logging frameworks etc. I think most other programs which is the great majority still benefit from the safe default behavior Simon described but there is a place for a explicit function IMOLeo Laudouard
09/23/2021, 4:41 PMwithTimeout
and TimeoutCancellationException
, I understand that an easy solution is to directly use withTimeoutOrNull
.
The problem comes from integration with other libraries. We cannot forbid usage of withTimeout
.
I do not consider TimeoutCancellationException
to be a fatal exception, do you have an example ?simon.vergauwen
09/23/2021, 4:46 PMval either = try { Either.Right(f()) } catch(e: Throwable) { Either.Left(e) }
for now, rather than Either.catch
.simon.vergauwen
09/23/2021, 4:47 PMResult
which doesn’t catch fatal exceptions, and Arrow also offers computation blocks etc for themsimon.vergauwen
09/24/2021, 6:12 AMsimon.vergauwen
09/24/2021, 6:13 AM