<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> -> <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> -> <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=""> </span>// Currently possible:</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="">do</span> {</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="">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=""> <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=""> } <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=""> <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=""> } <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=""> <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=""> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <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=""> </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=""> </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=""> bar = bar, </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=""> </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="">), </span>// Has to not throw an error</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> 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=""> <span style="font-variant-ligatures: no-common-ligatures; color: #35568a" class="">where</span> bar > <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=""> </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=""> { </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=""> </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=""> </span>// Bar or baz was nil</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="">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=""> </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=""> </span>// Some Error occured</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="">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=""> </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=""> </span>// Another Error occured</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <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=""> </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=""> <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 < <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=""> <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=""> } <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=""> <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=""> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <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=""> </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=""> </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=""> <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=""> <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=""> </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 { </span>// Not 100% beautiful</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="">return</span></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="">catch</span> {</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="">return</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <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=""> </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=""> <br class="webkit-block-placeholder"></p><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="">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=""> <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=""> <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=""> </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=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><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="">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=""> <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=""> } <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=""> <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=""> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <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=""> </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=""> <br class="webkit-block-placeholder"></p><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="">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=""> <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=""> <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=""> </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=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</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 = <span class="" style="color: rgb(53, 86, 138);">try</span> test() <span class="" style="color: rgb(53, 86, 138);">catch</span> SomeError.SomeCase {</div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; color: rgb(53, 86, 138);"><span class="">} </span>catch<span class=""> {</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;"> <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 <<a href="mailto:liamdunn@me.com" class="">liamdunn@me.com</a>> 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> <span class="" style="color: rgb(53, 86, 138);">let</span> unwrapped = optional, result = <span class="" style="color: rgb(53, 86, 138);">try</span> test() <span class="" style="color: rgb(53, 86, 138);">else</span> {</div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal;">} <span class="" style="color: rgb(53, 86, 138);">catch</span> SomeError.SomeCase {</div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; color: rgb(53, 86, 138);"><span class="">} </span>catch<span class=""> {</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;"> <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 <span class="" style="font-family: Menlo; color: rgb(53, 86, 138);">guard</span><span style="font-family: Menlo;" class=""> </span><span class="" style="font-family: Menlo; color: rgb(53, 86, 138);">let</span><span style="font-family: Menlo;" class=""> unwrapped = optional </span>to show how <i class="">guard let</i> and the <i class="">catch</i> 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 <i class="">catch X</i> on the same line as the <i class="">try</i> 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 = <span class="" style="color: rgb(53, 86, 138);">try</span> test() <span class="" style="color: rgb(53, 86, 138);">catch</span> SomeError.SomeCase {</div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; color: rgb(53, 86, 138);"><span class="">} </span>catch<span class=""> {</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 14px;"> <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> coordinator = <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> {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(53, 86, 138);">let</span> documentsDirectoryURL = <span class="" style="color: rgb(53, 86, 138);">try</span> <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: <span class="" style="color: rgb(53, 86, 138);">nil</span>, create: <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;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(53, 86, 138);">let</span> persistentStoreFileName = <span class="" style="color: rgb(232, 35, 0);">"CoreDataStore.sqlite"</span></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(53, 86, 138);">let</span> 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;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(53, 86, 138);">try</span> <span class="" style="color: rgb(88, 126, 168);">coordinator</span>.addPersistentStoreWithType(<span class="" style="color: rgb(88, 126, 168);">NSSQLiteStoreType</span>, configuration: <span class="" style="color: rgb(53, 86, 138);">nil</span>, URL: persistentStoreURL, options: <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;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">} <span class="" style="color: rgb(53, 86, 138);">catch</span> MyError.Case1 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">} <span class="" style="color: rgb(53, 86, 138);">catch</span> MyError.Case2 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">} <span class="" style="color: rgb(53, 86, 138);">catch</span> MyError.Case3 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">} <span class="" style="color: rgb(53, 86, 138);">catch</span> AnotherError.Case1 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">} <span class="" style="color: rgb(53, 86, 138);">catch</span> AnotherError.Case2 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;">} <span class="" style="color: rgb(53, 86, 138);">catch</span> AnotherError.Case3 {</div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(53, 86, 138);"><span class="">} </span>catch<span class=""> {</span></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;"> <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 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 <<a href="mailto:kametrixom@icloud.com" class="">kametrixom@icloud.com</a>> 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=""> <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=""> <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=""> <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=""> <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=""> <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="">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=""> <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=""> <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="">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=""> <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=""> <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=""> <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=""> <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=""> <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=""> <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=""> <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=""> <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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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 <i class="">try</i> as a keyword placed before every <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 <i class="">if let. </i>This ended up causing the “pyramid of doom” so often that in Swift 2.0, <i class="">guard let</i> 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> coordinator = <span class="" style="color: rgb(112, 61, 170);">NSPersistentStoreCoordinator</span>(managedObjectModel: <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> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <br class="webkit-block-placeholder"></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> documentsDirectoryURL = <span class="" style="color: rgb(187, 44, 162);">try</span> <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: <span class="" style="color: rgb(187, 44, 162);">nil</span>, create: <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;"> <br class="webkit-block-placeholder"></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> persistentStoreFileName = <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;"> <span class="" style="color: rgb(187, 44, 162);">let</span> 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;"> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">do</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> <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: <span class="" style="color: rgb(187, 44, 162);">nil</span>, URL: persistentStoreURL, options: <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;"> }</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> AnotherError.Case1 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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> AnotherError.Case2 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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> AnotherError.Case3 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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;"><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> <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;"> <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> <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;"> <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> <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;"> <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=""> {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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 <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 <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 <i class="">catch</i> clause to be used directly after any function that <i class="">throw</i>s. This clause includes all the <i class="">catch x {} catch y {}</i> error-handling code. Just like the <i class="">else</i> clause in a <i class="">guard let</i>, this <i class="">catch</i> clause has to return 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> coordinator = <span class="" style="color: rgb(112, 61, 170);">NSPersistentStoreCoordinator</span>(managedObjectModel: <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> documentsDirectoryURL = <span class="" style="color: rgb(187, 44, 162);">try</span> <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: <span class="" style="color: rgb(187, 44, 162);">nil</span>, create: <span class="" style="color: rgb(187, 44, 162);">false</span>) <span class="" style="color: rgb(187, 44, 162);">catch</span> {</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> MyError.Case1 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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> MyError.Case2 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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> MyError.Case3 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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;">}</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> persistentStoreFileName = <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=""> persistentStoreURL = </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> <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: <span class="" style="color: rgb(187, 44, 162);">nil</span>, URL: <span class="" style="color: rgb(79, 129, 135);">persistentStoreURL</span>, options: <span class="" style="color: rgb(187, 44, 162);">nil</span>) <span class="" style="color: rgb(187, 44, 162);">catch</span> {</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> AnotherError.Case1 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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> AnotherError.Case2 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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> AnotherError.Case3 {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"> <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;">}</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 <i class="">try</i> statement goes with which <i class="">catch </i>statements. In addition, the the pyramid of doom is gone, and the resulting code is reminiscent of a function with many <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"> </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>