[swift-evolution] [Proposal] Typed throws

Anton Zhilin antonyzhilin at gmail.com
Wed Feb 22 07:10:39 CST 2017


How about this:

func bypassRethrows<E: Error>(_ f: () throws(E) -> ()) throws(E) {
    if let e = (MyError() as Error) as? E {
        throw e
    }
}

I obviously can’t “test” this right now, but should work?

2017-02-22 3:42 GMT+03:00 Colin Barrett <colin at springsandstruts.com>:

On Sun, Feb 19, 2017 at 2:34 PM Anton Zhilin via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> Now that I think about it, generic throws does not exactly cover rethrows
>> .
>> Firstly, rethrows has semantic information that function itself does not
>> throw—it would be lost.
>>
> That's not true. Parametric polymorphism guarantees that rethrows and
> polymorphic throw are the same.
>
> For example, you can prove that as a consequence of parametricity that
> there is only one (pure) function in the of the set of all functions with
> the type ``forall A. A -> A'' and furthermore that it is the identity
> function.
>
> The intuition behind this is that you (meaning the fiction; imagine being
> a function!) cannot construct your own value of "A" since you don't have
> any information about what "A" is. The only place to get an "A" is from
> your argument.
>
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170222/b14b6323/attachment.html>


More information about the swift-evolution mailing list