<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Aug 17, 2017, at 11:27 PM, John McCall via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">The only practical merit of typed throws I have ever seen someone demonstrate is that it would let them use contextual lookup in a throw or catch.</span></div></blockquote></div><div class=""><br class=""></div><div class="">Let me take this in a slightly different direction.</div><div class=""><br class=""></div><div class="">I largely agree with you that most code shouldn't limit the types of errors it can throw. But I still want still want typed throws because I want to address a completely different problem: generics. Other than the useful but limited abilities of `rethrows`, there is currently no way to sensibly abstract over the error behavior of a piece of code. In particular, there's no way for a single protocol to support both throwing and non-throwing conformances.</div><div class=""><br class=""></div><div class="">One very straightforward and sensible way to handle this would be to support typed `throws` and make `Never` a subtype of `Error`; then you could handle error behavior abstraction using generic parameters, associated types, `where` clauses, and all those nice things we've already invented and taught people how to use. The other alternative is to invent several generics features from whole cloth purely to handle `throws`.</div><div class=""><br class=""></div><div class="">If we want to support errors in generics, designing typed `throws` and its interactions with the generics system seems a lot easier than designing a novel mechanism. Perhaps there are complications I'm not aware of—the thought of figuring out how generics are implemented fills me with dread—but naïvely, I would guess that the typed-throws-based solution will be easier to implement, too. And of course typed `throws` also helps the people who think they want to, you know, specify the type that a function throws. And it might help with the systems programming challenges we've talked about in this thread. So we can solve several different problems with a single feature, even if we think some of those problems are kind of niche.</div><div class=""><br class=""></div><div class="">I don't think any of the individual reasons to support typed `throws` are home runs, but I think this thread has produced some pretty solid ground balls and a couple of well-timed bunts, and that might be enough to get it across home plate.</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class=""><div style="font-size: 12px; " class="">-- </div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>
</div>
<br class=""></body></html>