Exception Annotations: Lay of the Land
I don’t know what the original motivation was for clearing the context of SomeException; if someone does, please do let me know, I’d love to know. Now that we are here though, I hesitate to argue that we should stop doing that; there are a lot of puzzle pieces here that need to fit together just so, and it’s difficult to be sure what happens when we change something quite so central as SomeException itself. Your toExceptionPreservingContext proposal at least separates out these concerns; if we conclude that the behaviour of toException for SomeException is the right one, then perhaps something like that might be useful. It would still be quite confusing though that throwIO (ExceptionWithContext ctxt e) would not actually use that context ctxt though! Personally I think we should change the behaviour and simply drop the requirement that the context must be empty, but it’s hard to be sure.
As for your question about the two backtraces: yes, you are correct. That’s why we have catchNoPropagate and rethrowIO.
Discussion in the ATmosphere