<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 class="">I actually half agree with you that this behaviour would be conceptually related to the do-catch block (although not a specific catch statement). So maybe alternatively the shorthand for this-</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">&nbsp; &nbsp; do</span><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;{</span></div><div style="margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">try</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">throwingFunction</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">()</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; } </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">catch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> MyError.TheError {</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// do something</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; } </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">catch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp;&nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">fatalError</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">"Expected error?"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div></div></div><div class=""><br class=""></div><div class="">could be instead-</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">&nbsp; &nbsp; do</span><span style="font-variant-ligatures: no-common-ligatures" class="">! {</span></div><div style="margin: 0px; line-height: normal; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">try</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">throwingFunction</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">()</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; } </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">catch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> MyError.TheError {</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// do something</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div></div></div><div class=""><br class=""></div><div class="">This would also avoid any conflict with existing behaviour.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Simon</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 6 May 2017, at 1:26 pm, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">_If_ this is something that's important, then the ! should follow 'catch' and not 'try'.<br class=""><br class="">The keyword 'try!' already means something, and it's not that. People may already mix try! and try in a do block and the behavior cannot be changed for source compatibility.<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Sat, May 6, 2017 at 15:16 Simon Pilkington via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">As a number of recent threads have shown, typed throws and error handling is a complicated topic with a lot of implications.<div class=""><br class=""></div><div class="">However in the mean time we could potentially address one of the pain points people give for wanting typed throws - exhaustive catch statements.</div><div class=""><br class=""></div><div class="">For functions that you completely control, it is possible to be completely certain of the errors the function will throw and it is an unrecoverable logical error for any other error to be thrown. Currently this situation would have to be handled like so-</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">do</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">try</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures" class="">throwingFunction</span><span style="font-variant-ligatures: no-common-ligatures;" class="">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">catch</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;MyError.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">TheError</span><span style="font-variant-ligatures:no-common-ligatures" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;theContext)</span>&nbsp;{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures" class="">// do something</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures" class="">catch</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)" class="">fatalError</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">“Impossible error?"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div></div><div class=""><br class=""></div><div class="">Here, the catch-all is just boilerplate to make the catch statement exhaustive but doesn’t provide any value to the programmer. Would it make sense to provide a shorthand for this case like this-</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">do</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">try</span><span style="font-variant-ligatures: no-common-ligatures;" class="">!&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures" class="">throwingFunction</span><span style="font-variant-ligatures: no-common-ligatures;" class="">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">catch</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;MyError.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">TheError</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class="">&nbsp;theContext)&nbsp;</span>{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures:no-common-ligatures" class="">// do something</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div></div><div class=""><br class=""></div><div class="">Where the&nbsp;<span style="color:rgb(186,45,162);font-family:Menlo;font-size:11px;font-variant-ligatures:no-common-ligatures" class="">try</span><span style="font-family:Menlo;font-size:11px;font-variant-ligatures:no-common-ligatures" class="">!</span>&nbsp;still indicates the call could fatalError if the function throws an unmatched error but allows the programmer to specify the errors that they specifically want to handle. I don’t think this moves the language away from the possibility of typed throws; adding typed throws would likely cause a warning in both cases - either to remove the catch-all or all the ! - if the compiler could determine the catch was now exhaustive without them.</div><div class=""><br class=""></div><div class="">If this has been proposed elsewhere I apologise.&nbsp;</div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Simon</div></div>_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></body></html>