[Pitch N+1] Typed Throws

I'm not sure that's the correct interpretation. Or at least, it's not the only viable interpretation. I find that section of that internal compiler documentation very hard to understand in any case, but as best I can decipher it seems to say a rethrowing function can throw only if a function it calls throws - it does not specifically say the thrown error has to be passed up as-is. I interpret it as alluding only to the timing at which an exception can be thrown, not any restriction on what is thrown.

The actual Swift Language Reference describes rethrows much more clearly and explicitly says catching and throwing a different exception is permitted:

A rethrowing function or method can contain a throw statement only inside a catch clause. This lets you call the throwing function inside a do -catch statement and handle errors in the catch clause by throwing a different error.

I think the actual Language Reference is the authoritative definition of intended functionality, because it's what the users of Swift actually learn from and rely on. Even if somehow its definition of rethrows was technically inaccurate at some point, it's now the definition de facto.

4 Likes