Ahmed Ibrahim
01/04/2021, 3:01 PMCancellationException?
For example I have
class MyApplicationDomainException(val cause: Exception /* The cause could be CancellationException */ ) : Exception
Now when I handle that exception,
myUseCase.fold(success = { }, failure = { exception -> if (exception.cause is CancellationException) throw exception.cause else handleException(exception) }
Now the drawback of this approach is that everytime I do the fold, I have to do that if statement.
Another problem is that CancellationException could be wrapped several levels inside the cause so I have to unwrap it in order to rethrow it.
I'm interested to know how other devs handle such cases. Maybe I need to try a different approach?