<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><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="">Hi Liam, this is how I imagine it working, I proposed three slightly different syntax rules:</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: #35568a" class="">enum</span> Error : <span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">ErrorType</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">case</span> Some }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">func</span> test(bar: <span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">Int</span>?, baz: <span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">Bool</span>?, foo: <span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">String</span> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">throws</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">Void</span>, qux: () <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">throws</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">Double</span>) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span>// Currently possible:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">do</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> foo(<span style="font-variant-ligatures: no-common-ligatures; color: #e82300" class="">"Hello"</span>)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">let</span> x = <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> qux()</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; } <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> Error.Some {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">print</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #e82300" class="">"Error!"</span>)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; } <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">print</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #e82300" class="">"Error!"</span>)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span>// First syntax:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(53, 86, 138);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span>guard<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>let</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; bar = bar,&nbsp; </span>// Has to be non-nil</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" 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: #35568a" class="">try</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> foo(</span><span style="font-variant-ligatures: no-common-ligatures; color: #e82300" class="">"Hello"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">), &nbsp; </span>// Has to not throw an error</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; x = <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> qux()</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">where</span> bar &gt; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">10</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">else</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {&nbsp; &nbsp; </span>// Has to not throw an error</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" 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: #35568a" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span>// Bar or baz was nil</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; } <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> Error.Some {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" 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: #35568a" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span>// Some Error occured</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; } <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" 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: #35568a" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; </span>// Another Error occured</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span>// `else` has to be there for optional, `catch` for errors</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">guard</span> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> foo(<span style="font-variant-ligatures: no-common-ligatures; color: #e82300" class="">"Hello"</span>), <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">let</span> x = <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> qux() <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">where</span> x &lt; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">10</span> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> Error.Some {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; } <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span>// Results can be ignored; catch can be on new line</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(53, 86, 138);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span>guard<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>let</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">_</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> foo(<span style="font-variant-ligatures: no-common-ligatures; color: #e82300" class="">"Hello"</span>),</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">_</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> qux()</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> Error.Some {&nbsp; </span>// Not 100% beautiful</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; } <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span>// Second syntax, no error matching, my personal preference</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">guard</span> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> foo(<span style="font-variant-ligatures: no-common-ligatures; color: #e82300" class="">"Hello"</span>), <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">let</span> x = <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> qux() <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">switch</span> error {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">case</span> Error.Some: <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(53, 86, 138);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>default<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span>return</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">guard</span> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">let</span> bar = bar, <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">_</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> qux() <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">where</span> baz == <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">true</span> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">else</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; } <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(207, 135, 36);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span>// Third syntax, `else` for everything, implicit `error` variable when a `try` was used in the guard</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">guard</span> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> foo(<span style="font-variant-ligatures: no-common-ligatures; color: #e82300" class="">"Hello"</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">else</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">switch</span> error {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">case</span> Error.Some: <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(53, 86, 138);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>default<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span>return</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">I think this feels right at home in Swift, `guard` indicating that some condition has to be met or else exit the scope. This syntax</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;">let result =&nbsp;<span class="" style="color: rgb(53, 86, 138);">try</span>&nbsp;test()&nbsp;<span class="" style="color: rgb(53, 86, 138);">catch</span>&nbsp;SomeError.SomeCase {</div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; color: rgb(53, 86, 138);"><span class="">}&nbsp;</span>catch<span class="">&nbsp;{</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal;">}</div></div></div></div></blockquote></div></div></blockquote><br class=""></div><div class="">you proposed doesn’t make it really clear that the scope has to be exited but I like it nonetheless. This also is in the same spirit as the recent discussion on making `if else`, `switch case` and such work as expression.</div><div class=""><br class=""></div><div class="">– Kame</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 07 Dec 2015, at 18:40, Liam Butler-Lawrence &lt;<a href="mailto:liamdunn@me.com" class="">liamdunn@me.com</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=""><div class="">Hey Kametrixom,</div><div class=""><br class=""></div><div class="">Thanks for the feedback! I agree that the proposed syntax needs improvement.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(53, 86, 138);">guard</span>&nbsp;<span class="" style="color: rgb(53, 86, 138);">let</span>&nbsp;unwrapped = optional, result =&nbsp;<span class="" style="color: rgb(53, 86, 138);">try</span>&nbsp;test()&nbsp;<span class="" style="color: rgb(53, 86, 138);">else</span>&nbsp;{</div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal;">}&nbsp;<span class="" style="color: rgb(53, 86, 138);">catch</span>&nbsp;SomeError.SomeCase {</div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; color: rgb(53, 86, 138);"><span class="">}&nbsp;</span>catch<span class="">&nbsp;{</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal;">}</div></div></div></div></blockquote></div><div class=""><br class=""></div><div class="">I like this example, but it seems rather specific. Are you just using the &nbsp;<span class="" style="font-family: Menlo; color: rgb(53, 86, 138);">guard</span><span style="font-family: Menlo;" class="">&nbsp;</span><span class="" style="font-family: Menlo; color: rgb(53, 86, 138);">let</span><span style="font-family: Menlo;" class="">&nbsp;unwrapped = optional&nbsp;</span>to show how&nbsp;<i class="">guard let</i>&nbsp;and the&nbsp;<i class="">catch</i>&nbsp;block could be used together, or suggesting that guard let should be required for this functionality? If the latter, how would we handle throwing functions that don’t return a value?</div><div class=""><br class=""></div><div class="">I’m fine with removing the enclosing catch { } from my original suggestion; perhaps something like this? My only concern with this is that it’s slightly confusing to have the first&nbsp;<i class="">catch X</i>&nbsp;on the same line as the&nbsp;<i class="">try</i>&nbsp;call.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;">let result =&nbsp;<span class="" style="color: rgb(53, 86, 138);">try</span>&nbsp;test()&nbsp;<span class="" style="color: rgb(53, 86, 138);">catch</span>&nbsp;SomeError.SomeCase {</div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; color: rgb(53, 86, 138);"><span class="">}&nbsp;</span>catch<span class="">&nbsp;{</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal;">}</div></div></div></div></blockquote></div><div class=""><br class=""></div><div class="">Also, regarding the new syntax being redundant:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(53, 86, 138);">let</span>&nbsp;coordinator =&nbsp;<span class="" style="color: rgb(195, 89, 0);">NSPersistentStoreCoordinator</span>(managedObjectModel: managedObjectModel)</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;"><br class=""></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(53, 86, 138);">do</span>&nbsp;{</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(53, 86, 138);">let</span>&nbsp;documentsDirectoryURL =&nbsp;<span class="" style="color: rgb(53, 86, 138);">try</span>&nbsp;<span class="" style="color: rgb(195, 89, 0);">NSFileManager</span>.<span class="" style="color: rgb(88, 126, 168);">defaultManager</span>().<span class="" style="color: rgb(88, 126, 168);">URLForDirectory</span>(.<span class="" style="color: rgb(88, 126, 168);">DocumentDirectory</span>, inDomain: .UserDomainMask, appropriateForURL:&nbsp;<span class="" style="color: rgb(53, 86, 138);">nil</span>, create:&nbsp;<span class="" style="color: rgb(53, 86, 138);">false</span>)</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(53, 86, 138);">let</span>&nbsp;persistentStoreFileName =&nbsp;<span class="" style="color: rgb(232, 35, 0);">"CoreDataStore.sqlite"</span></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(53, 86, 138);">let</span>&nbsp;persistentStoreURL = documentsDirectoryURL.<span class="" style="color: rgb(88, 126, 168);">URLByAppendingPathComponent</span>(persistentStoreFileName)</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(53, 86, 138);">try</span>&nbsp;<span class="" style="color: rgb(88, 126, 168);">coordinator</span>.addPersistentStoreWithType(<span class="" style="color: rgb(88, 126, 168);">NSSQLiteStoreType</span>, configuration:&nbsp;<span class="" style="color: rgb(53, 86, 138);">nil</span>, URL: persistentStoreURL, options:&nbsp;<span class="" style="color: rgb(53, 86, 138);">nil</span>)</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">}&nbsp;<span class="" style="color: rgb(53, 86, 138);">catch</span>&nbsp;MyError.Case1 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">}&nbsp;<span class="" style="color: rgb(53, 86, 138);">catch</span>&nbsp;MyError.Case2 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">}&nbsp;<span class="" style="color: rgb(53, 86, 138);">catch</span>&nbsp;MyError.Case3 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">}&nbsp;<span class="" style="color: rgb(53, 86, 138);">catch</span>&nbsp;AnotherError.Case1 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">}&nbsp;<span class="" style="color: rgb(53, 86, 138);">catch</span>&nbsp;AnotherError.Case2 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">}&nbsp;<span class="" style="color: rgb(53, 86, 138);">catch</span>&nbsp;AnotherError.Case3 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(53, 86, 138);"><span class="">}&nbsp;</span>catch<span class="">&nbsp;{</span></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">}</div></div></div></blockquote><br class=""></div><div class="">Thanks for pointing out this possibility. However, this code makes it even harder to decipher where MyError will be thrown from. How about AnotherError– which function threw that? No way to know. In certain cases that may not be an issue, but what if the error handling code presented a UI error? I might want to know more than just what the error is, but the context in which it was generated as well. Putting all the catch blocks at the end directly impacts readability.</div><div class=""><br class=""></div><div class="">As an extension of this issue, suppose that both throwing functions threw the same kind of error. If I want to&nbsp;use a different response based on which function call actually threw the error, I simply can’t do that using this method.</div><div class=""><br class=""></div><div class="">Look forward to hearing your thoughts. Thanks again!</div><div class=""><br class=""></div><div class="">Liam</div><div class=""><br class=""></div><div style="" class=""><blockquote type="cite" class=""><div class="">On Dec 7, 2015, at 10:49 AM, Kametrixom Tikara &lt;<a href="mailto:kametrixom@icloud.com" class="">kametrixom@icloud.com</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="">Hi Liam<div class=""><br class=""></div><div class="">I really like that idea, maybe the syntax needs a bit of adjustment. What do you think about this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">guard</span> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">let</span> unwrapped = optional, result = <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> test() <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">else</span> {</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal;" class="">} <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> SomeError.SomeCase {</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; color: rgb(53, 86, 138);" class=""><span style="" class="">} </span>catch<span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal;" class="">}</div></div></div><div class=""><br class=""></div><div class="">However I don’t really know if this is needed since it’s possible to call as many throwing functions as you want in a do-catch block:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">let</span> coordinator = <span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">NSPersistentStoreCoordinator</span>(managedObjectModel: managedObjectModel)</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">do</span> {</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">let</span> documentsDirectoryURL = <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> <span style="font-variant-ligatures: no-common-ligatures; color: #c35900" class="">NSFileManager</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">defaultManager</span>().<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">URLForDirectory</span>(.<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">DocumentDirectory</span>, inDomain: .UserDomainMask, appropriateForURL: <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">nil</span>, create: <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">false</span>)</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">let</span> persistentStoreFileName = <span style="font-variant-ligatures: no-common-ligatures; color: #e82300" class="">"CoreDataStore.sqlite"</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">let</span> persistentStoreURL = documentsDirectoryURL.<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">URLByAppendingPathComponent</span>(persistentStoreFileName)</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">try</span> <span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">coordinator</span>.addPersistentStoreWithType(<span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">NSSQLiteStoreType</span>, configuration: <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">nil</span>, URL: persistentStoreURL, options: <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">nil</span>)</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">} <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> MyError.Case1 {</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">} <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> MyError.Case2 {</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">} <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> MyError.Case3 {</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">} <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> AnotherError.Case1 {</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">} <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> AnotherError.Case2 {</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">} <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">catch</span> AnotherError.Case3 {</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(53, 86, 138);" class=""><span style="" class="">} </span>catch<span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">Which makes the need of such a feature redundant. I really like the idea and would love this to be added :)</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 07 Dec 2015, at 16:24, Liam Butler-Lawrence 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=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="">I completely agree Wei. Using&nbsp;<i class="">try</i>&nbsp;as a keyword placed before every&nbsp;<i class="">throw</i>ing function is one of the greatest strengths of Swift’s error-handling model.</div><div class=""><br class=""></div><div class="">I do have a new proposal regarding do/try/catch (if I should post this in a new thread, please let me know):</div><div class=""><br class=""></div><div class="">————</div><div class=""><br class=""></div><div class=""><b class="">The problem:</b></div><div class=""><br class=""></div><div class="">In Swift 1.0, the only way to conditionally unwrap an optional was with&nbsp;<i class="">if let.&nbsp;</i>This ended up causing the “pyramid of doom” so often that in Swift 2.0,&nbsp;<i class="">guard let</i>&nbsp;was introduced.</div><div class=""><br class=""></div><div class="">The same problem is present with do/try/catch. Consider this code snippet:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;coordinator =&nbsp;<span class="" style="color: rgb(112, 61, 170);">NSPersistentStoreCoordinator</span>(managedObjectModel:&nbsp;<span class="" style="color: rgb(79, 129, 135);">managedObjectModel</span>)</div></div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">do</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;documentsDirectoryURL =&nbsp;<span class="" style="color: rgb(187, 44, 162);">try</span>&nbsp;<span class="" style="color: rgb(112, 61, 170);">NSFileManager</span>.<span class="" style="color: rgb(61, 29, 129);">defaultManager</span>().<span class="" style="color: rgb(61, 29, 129);">URLForDirectory</span>(.<span class="" style="color: rgb(61, 29, 129);">DocumentDirectory</span>, inDomain: .UserDomainMask, appropriateForURL:&nbsp;<span class="" style="color: rgb(187, 44, 162);">nil</span>, create:&nbsp;<span class="" style="color: rgb(187, 44, 162);">false</span>)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;persistentStoreFileName =&nbsp;<span class="" style="color: rgb(209, 47, 27);">"CoreDataStore.sqlite"</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;persistentStoreURL = documentsDirectoryURL.<span class="" style="color: rgb(61, 29, 129);">URLByAppendingPathComponent</span>(persistentStoreFileName)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">do</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">try</span>&nbsp;<span class="" style="color: rgb(79, 129, 135);">coordinator</span>.<span class="" style="color: rgb(61, 29, 129);">addPersistentStoreWithType</span>(<span class="" style="color: rgb(112, 61, 170);">NSSQLiteStoreType</span>, configuration:&nbsp;<span class="" style="color: rgb(187, 44, 162);">nil</span>, URL: persistentStoreURL, options:&nbsp;<span class="" style="color: rgb(187, 44, 162);">nil</span>)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;AnotherError.Case1 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;AnotherError.Case2 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;AnotherError.Case3 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;<span class="" style="color: rgb(79, 129, 135);">MyError</span>.Case1 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;<span class="" style="color: rgb(79, 129, 135);">MyError</span>.Case2 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;<span class="" style="color: rgb(79, 129, 135);">MyError</span>.Case3 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);">catch<span class="" style="">&nbsp;{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div><div class=""><br class=""></div><div class="">First, yes, I know that URLForDirectory() doesn’t throw MyError. I’m illustrating the common pattern using actual function calls.</div><div class=""><br class=""></div><div class="">I see two problems with the above code:</div><div class=""><br class=""></div><div class="">1. The standard execution of code (if no errors are thrown) gets more and more nested with every call to a&nbsp;<i class="">throw</i>ing function, causing a pyramid of doom. There’s only two levels in this example, but it could easily be four or five.</div><div class=""><br class=""></div><div class="">2. The first&nbsp;<i class="">try NSFileManager.default</i>… is no less than 20 lines away from its catch statement. Again, with more try statements, this number only increases, making the code very unreadable in my opinion.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><b class="">A possible solution:</b></div><div class=""><br class=""></div><div class="">Allow a&nbsp;<i class="">catch</i>&nbsp;clause to be used directly after any function that&nbsp;<i class="">throw</i>s. This clause includes all the&nbsp;<i class="">catch x {} catch y {}</i>&nbsp;error-handling code. Just like the&nbsp;<i class="">else</i>&nbsp;clause in a&nbsp;<i class="">guard let</i>, this&nbsp;<i class="">catch</i>&nbsp;clause has to&nbsp;return&nbsp;or otherwise break normal execution. Because of this, the overarching do {} catch {} blocks are no longer needed, and normal execution continues without continually increasing code indentation.</div><div class=""><br class=""></div><div class="">This is how the above code snippet might look if this solution was implemented:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;coordinator =&nbsp;<span class="" style="color: rgb(112, 61, 170);">NSPersistentStoreCoordinator</span>(managedObjectModel:&nbsp;<span class="" style="color: rgb(79, 129, 135);">managedObjectModel</span>)</div><div class="" style="margin: 0px; line-height: normal;"><br class=""></div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;documentsDirectoryURL =&nbsp;<span class="" style="color: rgb(187, 44, 162);">try</span>&nbsp;<span class="" style="color: rgb(112, 61, 170);">NSFileManager</span>.<span class="" style="color: rgb(61, 29, 129);">defaultManager</span>().<span class="" style="color: rgb(61, 29, 129);">URLForDirectory</span>(.<span class="" style="color: rgb(61, 29, 129);">DocumentDirectory</span>, inDomain: .UserDomainMask, appropriateForURL:&nbsp;<span class="" style="color: rgb(187, 44, 162);">nil</span>, create:&nbsp;<span class="" style="color: rgb(187, 44, 162);">false</span>)&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;MyError.Case1 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;MyError.Case2 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;MyError.Case3 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;persistentStoreFileName =&nbsp;<span class="" style="color: rgb(209, 47, 27);">"CoreDataStore.sqlite"</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);"><span class="" style="color: rgb(187, 44, 162);">let</span><span class="" style="">&nbsp;persistentStoreURL =&nbsp;</span>documentsDirectoryURL<span class="" style="">.</span><span class="" style="color: rgb(61, 29, 129);">URLByAppendingPathComponent</span><span class="" style="">(</span>persistentStoreFileName<span class="" style="">)</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);"><span class="" style=""><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">try</span>&nbsp;<span class="" style="color: rgb(79, 129, 135);">coordinator</span>.<span class="" style="color: rgb(61, 29, 129);">addPersistentStoreWithType</span>(<span class="" style="color: rgb(112, 61, 170);">NSSQLiteStoreType</span>, configuration:&nbsp;<span class="" style="color: rgb(187, 44, 162);">nil</span>, URL:&nbsp;<span class="" style="color: rgb(79, 129, 135);">persistentStoreURL</span>, options:&nbsp;<span class="" style="color: rgb(187, 44, 162);">nil</span>)&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;AnotherError.Case1 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;AnotherError.Case2 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;AnotherError.Case3 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">catch</span>&nbsp;{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div><div class=""><br class=""></div><div class="">The syntax of the new catch block could certainly be improved on (it might also benefit from typed throwing as discussed in another thread). However, even imperfect, this code is much more readable than what’s currently required, as one can instantly tell which&nbsp;<i class="">try</i>&nbsp;statement goes with which&nbsp;<i class="">catch&nbsp;</i>statements. In addition, the the pyramid of doom is gone, and the resulting code is reminiscent of a function with many&nbsp;<i class="">guard let</i>s.</div><div class=""><br class=""></div><div class="">If you have any feedback or know of potential issues that I’m not aware of, I look forward to hearing from you. Thanks so much!</div><div class=""><br class=""></div><div class="">Liam</div></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=UMghxGHOvTEcVGG3PKHzuJe-2F1jwKPcDcSNH0SiRhP14efm2rg3VN23A4VXqdP-2B7orIRyJQKvbO3ps-2BSrqWGI-2BRqG3rkoeV5q46Eipa2Mx-2F-2B7rY1J0KN7MuNRB8jLyIWotkDQ0lCMhoCQ8X6GtRRR4PLPvoRBp5VdgAJtRUBg3OgSk11dYWbbhN5myO-2FmiZZ-2FGIJBRPsLUWfPsnAVLttgeJxFIBTSwzRodSV-2B9MxnEao-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span>_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>