What is your evaluation of the proposal?
Very much for; it is well thought-out regarding trade-offs and does not go ahead to implement more than can be implemented right now without too far-ranging consequences.
Is the problem being addressed significant enough to warrant a change to Swift?
Definitely. Though the original rationale for only supporting untyped throws did make sense in its own way, it is not a one-size-fits-all solution. The introduction of Result
did much to undo the original Swift way of untyped errors whilst at the same time introducing an impedance mismatch between throws
and Result
as well as Result.init(catching:)
and Result.get()
There are many cases where all the possible errors indeed can be clearly enumerated, such as formatting and parsing functions. The rationale that client code is made more resilient toward updates in errors throws by libraries is also a bit of a fiction as libraries may, at their leisure, not only add error cases, but also rename and remove old ones, breaking client code. This recently happened with PhoneNumberKit, I think.
Sometimes, I have even just wished I could restrict errors to a general error type such as any LocalizedError
or RecoverableError
, but not even that has been possible, complicating code or making it not worthwhile to implement.
Does this proposal fit well with the feel and direction of Swift?
Yes, mostly.
I am not crazy about the spelling of throws(Error)
but will take it if it makes specifying the error thrown possible.
Likewise, I would have hoped that it would be possible to throw more than one error type and exhaustively catch them one by one in a catch
block, as I have a habit of collapsing adjacent throwing function calls into one do
block, but I take it that this proposal does not preclude revisiting that possibility at a later date.
If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
Not exactly; if anything, I have used the opposite, where the catch or switch clause does not have to be exhaustive, so one may approximate typed throws but without the guarantees of exhaustiveness that make Swift use, and where the current state of catch
is an Ā»exceptionĀ«, if you might.
How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
I have read the proposal in its entirety as well as this thread from top to bottom.