<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 5, 2017, at 10:30 AM, 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></div></blockquote><div><br class=""></div><div>The nesting and ceremony, to me, were part of Swift’s philosophy of making error handling explicit. Merging catch blocks into guards saves you maybe 3-10 lines if you intended to actually handle the error(s), otherwise this effectively <font face="Menlo" class="">try?</font>’s into a failable pattern match. At which point, you have to wonder if the error-throwing function you wrote wouldn’t be better off just returning an Optional if you’re going to discard the semantic content of the error.</div><div><br class=""></div><div>~Robert Widmann</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><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="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>