Is it considered bad practice to catch
CancellationException, do custom shutdown/cleanup code, and then rethrow the exception?
If I have a suspend function that performs some operation, and want a way to cancel that operation, I may need to perform some steps to rollback the partial changes performed by that operation. Is it OK to do that in a
CancellationException? Or should cancellation procedures be left “untouched” as much as possible?
In the latter case, I can only imagine adding a separate “cancelOperation” function in the same API. Note that I was talking about an operation done by a suspend function, so the operation is done once that function no longer suspends. This means that I can’t just return some custom class that contains a “cancelOperation” function or a “dispose” function (COIL does the latter).