[swift-users] [swift-evolution] Best way to handle escaping function that might throw

Howard Lovatt howard.lovatt at gmail.com
Sat Jan 14 17:50:43 CST 2017


I am assuming Never is the subtype of all types, because any function
regardless of it's return type, including Void, can return Never.

On Fri, 13 Jan 2017 at 6:32 pm, Pierre Monod-Broca <
pierremonodbroca at gmail.com> wrote:

> @Howard
> I was thinking the same about the constraint.
>
> Does that mean that Never should be a subtype of Error (maybe it is
> already) ? Else you couldn't say throws(Never) or FSTore<Never>
>
> @Howard
> I'm not sure about <>, it should stay reserved for generics, IMHO.
>
> Pierre
>
> Le 13 janv. 2017 à 01:11, Howard Lovatt via swift-users <
> swift-users at swift.org> a écrit :
>
> @Anton, Yes that would work and we would get typed throws, which I like.
> As an aside, I think E would have to be constrained to be an Error, `<E:
> Error>`, and maybe `throws<E>` reads better because you are used to types
> in angle brackets.
>
>   -- Howard.
>
>
>
> On 13 January 2017 at 08:32, Anton Zhilin <antonyzhilin at gmail.com> wrote:
>
> The best way to deal with such situations should be typed throws. Then
> rethrows should be removed and replaced with generics in throws clause. E
> == Never ⇔ function does not throw.
>
>
> struct FStore<E> {
>
>     let f: () throws(E) -> Void
>
>     init(_ f: @escaping () throws(E) -> Void) { self.f = f }
>
>     func call() throws(E) { try f() }
>
> }
>
>
>
> let store = FStore<Never>({ print("Hello") })
>
> store.call()
>
> [Phase2]
>
>
>>
>
>
>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
> --
-- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170114/d4baf873/attachment.html>


More information about the swift-users mailing list