<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Has there been any progress on this? I came here to propose this but came upon this thread first.<div class=""><br class=""></div><div class="">This proposal goes way beyond sugar. I find myself constantly in the following situation:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c2349b" class="">let</span> observer = <span style="color: #93c96a" class="">Observer</span>(with: <span style="color: #93c96a" class="">CircuitBreaker</span>(holding: <span style="color: #c2349b" class="">self</span>))</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c2349b" class="">do</span> {</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color: #c2349b" class="">let</span> handlerDisposable = <span style="color: #c2349b" class="">try</span> startHandler(observer)</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class="">&nbsp; &nbsp; &nbsp; &nbsp; } <span style="color: #c2349b" class="">catch</span> {</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;observer.sendFailed(error)</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(40, 43, 53); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(147, 201, 106); background-color: rgb(40, 43, 53);" class=""><span style="color: #ffffff" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>cancelDisposable<span style="color: #ffffff" class=""> = </span>ActionDisposable<span style="color: #ffffff" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;observer.<span style="color: #93c96a" class="">sendInterrupted</span>()</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(40, 43, 53);" class=""><span style="color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;handlerDisposable<span style="text-decoration: underline" class="">?</span>.<span style="color: #93c96a" class="">dispose</span>() </span><font color="#e32400" class="">// Error!!!! handlerDisposable is not defined here</font></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div></div><div class=""><br class=""></div><div class="">It’s not as simple as putting it all in the do block because then I’ll be catching errors I might not want to catch! (In this case if the initializer of ActionDisposable was capable of throwing.)</div><div class=""><br class=""></div><div class="">This is my frustration with every language that has this style of error handling. FWIW, Scala is the only language that I have seen with this style of error handling that solves this problem. The built-in type `Try` combined with pattern matching fixes this issue of over extending the catch area. Which is kinda nifty and also bridges the functional gap as well.</div><div class=""><br class=""></div><div class=""><span class="pl-k" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; orphans: 2; white-space: pre; widows: 2; box-sizing: border-box; color: rgb(215, 58, 73);">object</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class=""> </span><span class="pl-en" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; orphans: 2; white-space: pre; widows: 2; box-sizing: border-box; color: rgb(111, 66, 193);">Try</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class=""> {</span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="pl-c" style="color: rgb(106, 115, 125); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; orphans: 2; white-space: pre; widows: 2; box-sizing: border-box;">/**</span><span style="color: rgb(106, 115, 125); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class=""> Constructs a `Try` using the by-name parameter.  This</span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: rgb(106, 115, 125); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; orphans: 2; white-space: pre; widows: 2; background-color: rgb(255, 255, 255);" class="">* method will ensure any non-fatal exception is caught and a</span></div><div class=""><div style="orphans: 2; widows: 2;" class=""><font color="#6a737d" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="white-space: pre; background-color: rgb(255, 255, 255);" class="">&nbsp;   </span></font><span style="color: rgb(106, 115, 125); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">* `Failure` object is returned.</span></div><div style="orphans: 2; widows: 2;" class=""><span style="color: rgb(106, 115, 125); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">    </span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(215, 58, 73);">def</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class=""> </span><span class="pl-en" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(111, 66, 193);">apply</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">[</span><span class="pl-en" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(111, 66, 193);">T</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">](</span><span class="pl-v" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(227, 98, 9);">r</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">: </span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(215, 58, 73);">=&gt;</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class=""> </span><span class="pl-en" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(111, 66, 193);">T</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">)</span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(215, 58, 73);">:</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class=""> </span><span class="pl-en" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(111, 66, 193);">Try</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">[</span><span class="pl-en" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(111, 66, 193);">T</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">] </span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(215, 58, 73);">=</span></div><div style="orphans: 2; widows: 2;" class=""><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">      </span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(215, 58, 73);">try</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class=""> </span><span class="pl-en" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(111, 66, 193);">Success</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">(r) </span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(215, 58, 73);">catch</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class=""> {</span></div><div style="orphans: 2; widows: 2;" class=""><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">        </span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(215, 58, 73);">case</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class=""> </span><span class="pl-en" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(111, 66, 193);">NonFatal</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">(e) </span><span class="pl-k" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(215, 58, 73);">=&gt;</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class=""> </span><span class="pl-en" style="font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; box-sizing: border-box; color: rgb(111, 66, 193);">Failure</span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">(e)</span></div><div style="orphans: 2; widows: 2;" class=""><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">      </span><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">}</span></div><div style="orphans: 2; widows: 2;" class=""><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">    }</span></div><div style="orphans: 2; widows: 2;" class=""><span style="color: rgb(36, 41, 46); font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">}</span></div></div><div class=""><br class=""></div><div class="">It also would make</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class=""><span style="color: rgb(194, 52, 155);" class="">try</span>&nbsp;startHandler(observer)&nbsp;<span style="color: rgb(194, 52, 155);" class="">catch</span>&nbsp;{</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class="">&nbsp; &nbsp; observer.sendFailed(error)</div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(255, 255, 255); background-color: rgb(40, 43, 53);" class="">}</div></div><div class=""><br class=""></div><div class="">an obvious extension which to me makes sense since it’s just treating the one function call expression as it’s own implicit do block.</div><div class=""><br class=""></div><div class="">Tyler</div><div class=""><br class=""></div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 11, 2017, at 10:31 AM, Christopher Kornher via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><br class="">Begin forwarded message:<br class=""><font color="#5856d6" class=""><br class=""></font><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">From: </b></span><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class="">Christopher Kornher &lt;<a href="mailto:ckornher@me.com" class="">ckornher@me.com</a>&gt;</span><br class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Subject: </b></span><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Re: [swift-evolution] [Pitch] Guard/Catch</b></span><br class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">Date: </b></span><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class="">July 10, 2017 at 5:10:15 PM MDT</span><br class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">To: </b></span><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class="">Elviro Rocca &lt;<a href="mailto:retired.hunter.djura@gmail.com" class="">retired.hunter.djura@gmail.com</a>&gt;</span><br class=""><font color="#5856d6" class=""><br class="">This messages was modified from the original</font>&nbsp;<font color="#5856d6" class="">accidentally&nbsp;</font><span style="color: rgb(88, 86, 214);" class="">sent out privately, earlier.</span></div><div class=""><font color="#5856d6" class=""><br class=""></font>FYI this works today in Xcode 9.0 beta 2 playgrounds:<br class=""><font color="#5856d6" class=""><br class=""></font>```<br class=""><span style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">class</span><span class="" style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px;"> X {</span><br class=""><span class="" style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px;">&nbsp; &nbsp;&nbsp;</span><span style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">init</span><span class="" style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px;">() </span><span style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">throws</span><span class="" style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px;"> {}</span><br class=""><font color="#d12f1b" class=""><br class=""></font><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">func</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> foo() {</span><br class=""><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(62, 30, 129);">print</span><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;">( </span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">"Things succeeded"</span><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;"> )</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">}</span><br class=""><font color="#d12f1b" class=""><br class=""></font><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">func</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> bar() </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">throws</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> -&gt; </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(79, 129, 135);">X</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; { </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">return</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">try</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(79, 129, 135);">X</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">() }</span><br class=""><font color="#d12f1b" class=""><br class=""><br class=""></font><span style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">func</span><span class="" style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px;"> f()</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">{</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">guard</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">let</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> x1:</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(79, 129, 135);">X</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> = </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">try</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">? </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(79, 129, 135);">X</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">(), </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">let</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> x2:</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(79, 129, 135);">X</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> = </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">try</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">? </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(49, 89, 93);">bar</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">() </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">else</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> {</span><br class=""><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(62, 30, 129);">print</span><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;">( </span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">"Things failed "</span><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;">)</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">return</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</span><br class=""><font color="#d12f1b" class=""><br class=""></font><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; x1.</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(49, 89, 93);">foo</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">()</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; x2.</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(49, 89, 93);">foo</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">()</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">}</span><br class=""><font color="#d12f1b" class=""><br class=""></font><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(49, 89, 93);">f</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">()&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(0, 132, 0);">// works</span><br class=""><span style="background-color: rgb(255, 255, 255);" class="">```</span><br class=""><font color="#ba2da2" face="Menlo" size="2" class=""><br class=""><br class=""></font>Most of the examples of this proposed feature don’t handle the exceptions other than to perform an early return.&nbsp;<br class="">So, without handing exceptions, &nbsp;the only unhandled case is a non-returning throwing function or init:<br class="">&nbsp;<br class="">```<br class=""><span style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">class</span><span class="" style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px;"> X {</span><br class=""><span class="" style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px;">&nbsp; &nbsp;&nbsp;</span><span style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">init</span><span class="" style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px;">() </span><span style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">throws</span><span class="" style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px;"> {}</span><br class=""><font color="#d12f1b" class=""><br class=""></font><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">func</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> foo() {</span><br class=""><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(62, 30, 129);">print</span><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;">( </span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">"Things succeeded"</span><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;"> )</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">}</span><br class=""><font color="#d12f1b" class=""><br class=""></font><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">func</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> bar() </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">throws</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">{ </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">let</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">_</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> =&nbsp; </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">try</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(79, 129, 135);">X</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">() }</span><br class=""><font color="#d12f1b" class=""><br class=""><br class=""></font><span style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">func</span><span class="" style="color: rgb(186, 45, 162); font-family: Menlo; font-size: 13px;"> f()</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">{</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">do</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> {</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">try</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(49, 89, 93);">bar</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">()</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; } </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">catch</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> {</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">return</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</span><br class=""><font color="#d12f1b" class=""><br class=""></font><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">guard</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">let</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> x:</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(79, 129, 135);">X</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> = </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">try</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">? </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(79, 129, 135);">X</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">() </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">else</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class=""> {</span><br class=""><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(62, 30, 129);">print</span><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;">( </span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">"Things failed "</span><span class="" style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px;">)</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(186, 45, 162);">return</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</span><br class=""><font color="#d12f1b" class=""><br class=""></font><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; x.</span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(49, 89, 93);">foo</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">()</span><br class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">}</span><br class=""><font color="#d12f1b" class=""><br class=""></font><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(49, 89, 93);">f</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 13px; background-color: rgb(255, 255, 255);" class="">()&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="" style="font-family: Menlo; font-size: 13px; color: rgb(0, 132, 0);">// works</span><br class=""><span style="color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class="">```</span><br class=""><font color="#5856d6" class=""><br class=""></font>Having to call a throwing, Void method before performing the rest of a non-throwing function (or closure ) seems like an edge case to me. Perhaps I am just biased by my experience. I have not created or used many throwing initializers and certainly none in guard statements, and if they were in guard statements, the need to handle exceptions differently from any other guard failure seems ever more unlikely.</div><div class=""><br class=""></div><div class="">I don’t think that the small rightward drift of exception handling is onerous. It is hardly like the “pyramid of doom” that ```guard``` was created to fix.</div><div class=""><br class=""></div><div class="">```</div><div class=""><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(186, 45, 162);" class="">func</span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class=""> f( y:</span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(112, 61, 170);" class="">Int</span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">? = </span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(186, 45, 162);" class="">nil</span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class=""> )</span></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">do</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">try</span> <span style="color: #31595d" class="">bar</span>()</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">let</span> x:<span style="color: #4f8187" class="">X</span> = <span style="color: #ba2da2" class="">try</span> <span style="color: #4f8187" class="">X</span>()</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">guard</span> <span style="color: #ba2da2" class="">let</span> y = y <span style="color: #ba2da2" class="">else</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3e1e81" class="">print</span>( <span style="color: #d12f1b" class="">"No y"</span>)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;" class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; x.<span style="color: #31595d" class="">foo</span>()</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3e1e81" class="">print</span>( <span style="color: #d12f1b" class="">"y=</span>\<span style="color: #d12f1b" class="">(</span>y<span style="color: #d12f1b" class="">)"</span>)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; } <span style="color: #ba2da2" class="">catch</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>// Handle some exceptions.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div class="">```</div></div><div class=""><br class=""></div><div class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-family: Helvetica; font-size: 12px;" class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""></div></div></div></div></div></div><div class="">On Jul 10, 2017, at 1:45 AM, Elviro Rocca via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><blockquote type="cite" class=""></blockquote><font color="#00afcd" class=""><br class=""></font>This is not a sugar proposal, in the same way as "guard" is not syntactic sugar, because it requires exiting the scope on the else branch, adding expressive power and safety to the call: also, the sugary part is pretty important because it avoids nested parentheses and very clearly states that if the guard condition is not fulfilled, the execution will not reach the next lines of code. Guard is useful to push the programmer to at least consider an early return instead of branching code paths, to achieve better clarity, readability and lower complexity, and I suspect is one of the best Swift features for many people.<br class=""><br class="">Also, the case that the proposal aims to cover is not an edge case at all for a lot of people, including me. Rethrowing an error is something that I almost never do, and I consider the "umbrella" do/catch at the top of the call stack an anti-pattern, but I understand that many people like it and I'm not arguing against it. I am arguing in favor of having options and not pushing a particular style onto programmers, and for my (and many people's) style, a guard/catch with forced return is an excellent idea. In fact you seem to agree on the necessity of some kind of forced-returnish catch but your elaborations don't seem (to me) much better than the proposal itself.<br class=""><br class="">Dave DeLong raised the point of weird behavior in the case of a function like:<br class=""><br class=""><br class="">func doSomething() throws → Result? { … }<br class=""><br class=""><br class="">In this case, what would the type of x be?<br class=""><br class=""><br class="">guard let x = try doSomething() catch { /// handle and return }<br class=""><br class=""><br class="">Simple, it would be Optional&lt;Result&gt;. I don't find this confusing at all, and if the idea that just by seeing "guard let" we should expect a non-Optional is somehow diffused, I think it's better to eradicate it.<br class=""><br class="">First of all, if I'm returning an optional from a throwing function, it's probably the case that I want the Optional to be there in the returned value: the only reason why I would consider doing that is if the semantics of Optional are pretty meaningful in that case. For example, when parsing a JSON in which I expect a String or null to be at a certain key:<br class=""><br class=""><br class="">extension&nbsp;String:&nbsp;Error&nbsp;{}<br class=""><br class="">func&nbsp;parseString(in dict: [String:Any], at key:&nbsp;String)&nbsp;throws&nbsp;-&gt;&nbsp;String? {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>guard&nbsp;let&nbsp;x = dict[key]&nbsp;else&nbsp;{&nbsp;throw&nbsp;"No value found at '\(key)' in&nbsp;\(dict)"&nbsp;}<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>if&nbsp;let&nbsp;x = x&nbsp;as?&nbsp;String&nbsp;{&nbsp;return&nbsp;x }<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>if&nbsp;let&nbsp;x = x&nbsp;as?&nbsp;NSNull&nbsp;{&nbsp;return&nbsp;nil&nbsp;}<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>throw&nbsp;"Value at '\(key)' in&nbsp;\(dict) is not 'string' or 'null"<br class="">}<br class=""><br class=""><br class="">Thus, if I'm returning an Optional from a throwing function it means that I want to clearly distinguish the two cases, so they shouldn't be collapsed in a single call:<br class=""><br class=""><br class="">guard let x = try doSomething() catch { /// handle and return }<br class="">guard let x = x else { /// handle and return }<br class=""><br class=""><br class="">Also, if a function returns something like "Int??", a guard-let (or if-let) on the returned value of that function will still bind an "Int?", thus unwrapping only "one level" of optional. If-let and guard-let, as of today, just unwrap a single optional level, an do not guaranteed at all that the bound value is not optional.<br class=""><br class="">To me guard-let (like if-let) is basically sugar for monadic binding for Optionals, with the additional expressivity granted by the forced return. I would love to see the same monadic binding structure applied to throwing functions.<br class=""><br class=""><br class=""><br class="">Elviro<br class=""><br class=""><br class=""><br class=""><font color="#00afcd" class=""><br class=""></font>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Il giorno 09 lug 2017, alle ore 01:16, Christopher Kornher via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; ha scritto:<br class=""><br class="">Thanks for you considerate reply. My concern over the proliferation of “sugar proposals” is a general one. This proposal has more merit and general utiliity than many others. I have never used a throwing function in a guard statement that was not itself in a throwing function, but I can see that it could possibly be common in some code. Wrapping a guard statement and all the code that uses variables set in the guard in a do/catch is sub-optimal.<br class=""><br class=""><br class="">All catches don’t have to exit the outer scope, so using guard only handles a subset&nbsp;<br class=""><br class="">It think that creating the terse try/catch for simple cases has multiple advantages:<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>1)&nbsp;I think that it addresses your desire for a simple way to use throwing functions easily in guard statements.<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>2)&nbsp;It avoids having to change the guard syntax to accomplish this<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>3)&nbsp;It is useful for handling simple one line try/catch constructs in less space in a way that should not seem too foreign to Swift developers.<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>4) It simplifies code that currently uses nested do/try/catch constructs. Even though this is rare, it introduces significant “rightward drift”.<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>5)&nbsp;It can used to return early from void throwing functions easily. e.g. :&nbsp;<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>```<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>```<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>Multiple void throwing functions would probably be better handled by a do/catch block, but there is no danger of needing values from these functions because there are none:<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>```<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>```<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>I did not think of this before, but perhaps we could allow `do` to be replaced with `guard`, thereby allowing values to escape to the outer scope, while still ensuring an early exit:<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>```<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>```<br class="">I am not sure that “leaky” braces are a good idea, so perhaps some other character could be used to indicate a non-scope or whatever you want to call it:<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>```<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>```<br class="">This would make the language even harder to read, so just using braces is probably a better idea.<br class=""><br class="">This would change the guard syntax slightly, but is a straightforward extrapolation of do/catch and guard, I think. Of course, this could replace the existing guard syntax entirely and its use of semicolons, if we want to go that far…<br class=""><br class="">Allowing this syntax only if one of the expressions throws is possibly a good backward-compatible solution that would avoid redundant guard syntaxes.<br class=""><br class="">Anyway there are lot of possibilities here. We are not forced to extend the guard statement as it exists today. The current guard statement syntax was quite controversial when it was introduced and extending it may not be the best option to do what you want.<br class=""><br class="">- Chris<br class=""><br class=""><br class=""><br class=""><br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""><blockquote type="cite" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""></blockquote>On Jul 8, 2017, at 4:16 PM, Benjamin Spratling via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""><br class=""><br class="">I’ve read your email, but haven’t digested it fully. &nbsp;One thing I agree with is that most functions which call throwing functions don’t actually use a do…catch block, but instead are merely marked “throws” and the error is propagated back through the stack. &nbsp;Once I seriously started coding functions with errors, I realized I almost always wanted my errors to reach my view-controller or my business logic so I could present separate UI if a real error occurred, and often my error message depended on the details of the error instance.<br class=""><br class=""><br class=""><br class="">I disagree with your conclusion on this point.<br class="">The “guard” syntax is specifically designed to achieve early return (and placing code associated with early return at the point where it happens) and cleanly installing the returned value into the surrounding scope. &nbsp;So far it has been used to achieve early return only with optionals, true. &nbsp;But is that inherent to ‘guard’, or is it merely because that’s the only way it has been used? &nbsp;The guard does set variables that are needed in the body of the function, and that’s exactly why using guard with values returned from throwing functions makes so much sense, because it does exactly the same thing in a general sense. &nbsp;The “do”…”catch” structure is intentionally designed differently, to place the “happy path” in one place and place the returns in another place. &nbsp;I think with guard/else, we’re seeing developers who can handle less cognitive loading find it easier to reason about early return than grouping failures after the happy path. &nbsp;This proposal hopes to introduce that better language architecture to the catching of errors.<br class=""><blockquote type="cite" class=""><div class=""><div style="text-align: start; text-indent: 0px;" class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></blockquote>On Jul 8, 2017, at 4:08 PM, Christopher Kornher &lt;<a href="mailto:ckornher@me.com" class="">ckornher@me.com</a>&gt; wrote:<br class=""><br class="">I am opposed to this proposal because it muddies up the language to support what is essentially an edge case. The standard way to exit a function early because an exception is thrown is to make the function itself throw, if it is part of a larger operation. The addition of a few lines of try/catch code is not a great burden and makes the termination of an an exception very clear.<br class=""><div class=""><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></blockquote><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></blockquote>`guard` statements are generally used to set variables that are needed in the body of a function. Using them to save a few lines of exception handing code is a very different use. There is no need to mix two relatively clean syntaxes for a few edge cases and increase cognitive load one more time,<span class="Apple-converted-space">&nbsp;</span><br class=""></div></div></div></div></blockquote><div class=""><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>guard try foo( ) catch { return }</div></div></div><span class="Apple-tab-span" style="white-space: pre;">        </span>do {<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>try fn1()<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>try fn2()<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>} catch {<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>// keep going,&nbsp;return or call a non-returning function, since throw is already handled by declaring a throwing enclosing function.<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>// No varibles are needed by the outer block because none are set<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>// So it is not clearly a guard-like statement<br class=""><div class=""><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}<span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;</div></div></div><span class="Apple-tab-span" style="white-space: pre;">        </span>guard {<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>try fn1()<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>try fn2()<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>let x = fn3()<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>} catch {<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>// Must exit<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>} else {<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>// Must exit<br class=""><div class=""><div class=""><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}<span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;</div></div></div></div><span class="Apple-tab-span" style="white-space: pre;">        </span>guard &lt;your favorite character here&gt;<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>try fn1()<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>try fn2()<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>let x = fn3()<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;&lt;another favorite character here&gt;&nbsp;catch {<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>// Must exit<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>} else {<br class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>// Must exit<br class=""><div class=""><div class=""><div class=""><div class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}<span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;</div></div></div></div></div><br class="">-Ben Spratling<br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><div class=""><div style="text-align: start; text-indent: 0px;" class=""><div class=""><div class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></div></div></div></div></div></div></div></blockquote></div></div></div></blockquote></div></div></div></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>