<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Jon — we explored allowing users to mix and match optional unwrapping and error catching in the same guard, but found that it was ultimately pretty confusing. We think that guard/else and guard/catch should be two totally different components. Dave’s email lays out the two best approaches, and the “Alternatives Considered” section of the proposal goes into why those alternatives were ultimately rejected.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 5, 2017, at 2:09 PM, Dave DeLong 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=""><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="">Soroush’s proposal has the idea that maybe we could do multiple blocks for this scenario, like so:<div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">guard try something(), let thing = optionalThing catch {</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> // try something() failed</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">} else {</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> // the let-binding failed</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">}</span></font></div><div class=""><br class=""></div><div class="">🤔 Alternatively, what if the “error” captured was optional in this scenario?</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">guard try something(), let thing = optionalThing catch {</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> if let error = error {</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> // the try call failed</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> } else {</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> // the optional binding failed</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> }</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">}</span></font></div><div class=""><br class=""></div><div class="">Dave</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jul 5, 2017, at 12:00 PM, Jon Shier 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=""><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=""><span class="Apple-tab-span" style="white-space:pre">        </span>I didn’t think I was going to like it but I really do. My only concern, which isn’t really a deal breaker, is what it would look like to chain multiple try and let statement in the same guard. Unless that scenario works well I don’t think you could convince others. i.e. In the case where I have:<div class=""><br class=""></div><div class="">guard try something(), let thing = optionalThing catch { }</div><div class=""><br class=""></div><div class="">What happens when the let fails? No implicit error?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Jon</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Jul 5, 2017, at 1:30 PM, Soroush Khanlou 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=""><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="">I’d like to propose a guard/catch construct to the language. It would allow code to use throwing functions and handle errors fully, without straying from a happy path. do/catch can be a bit heavy-handed sometimes, and it would be nice to be able to handle throwing functions without committing to all the nesting and ceremony of do/catch.</div><div class=""><br class=""></div><div class="">Full proposal, which discusses all the corner cases and alternatives:</div><div class=""><a href="https://gist.github.com/khanlou/8bd9c6f46e2b3d94f0e9f037c775f5b9" class="">https://gist.github.com/khanlou/8bd9c6f46e2b3d94f0e9f037c775f5b9</a></div><div class=""><br class=""></div><div class="">Looking forward to feedback!</div><div class=""><br class=""></div><div class="">Soroush</div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>