<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=""><br class=""><div><blockquote type="cite" class=""><div class="">Le 5 févr. 2016 à 14:33, Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class="">@Erica I wrote this example before:</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">do {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>let listener = try TCPListener("some address")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>do {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>let conn = try listener.accept()</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>// do some work and catch more errors</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>do {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                        </span>try conn.close()</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>} catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                        </span>do {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                                </span>try listener.close()</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                        </span>} catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                                </span>fatallError("cannot close listener")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                        </span>}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                        </span>fatallError("cannot close connection")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>} catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>fatallError("cannot accept")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">} catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>fatallError("cannot create listener")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>I am no expert (and have always be scared of throws) but from what I understand the errors thrown by each method can be specific, so you can do multiple try in a single do (even though I could not find example on the web); flattening your pyramid a little bit.</div><div><br class=""></div><div>do {</div><div> let listener = try TCPListener("some address")</div><div> let conn = try listener.accept()</div><div> // Some more code</div><div>} catch SomeError.CannotCreate {</div><div> fatallError("cannot create listener")</div><div>} catch SomeError.Rejection {</div><div> fatallError("cannot accept")</div><div>} catch {</div><div> fatallError("Unknown")</div><div>}</div><div><br class=""></div><div>So once restructured, is the pyramid still that bad?</div><div><br class=""></div><div>Dany</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class="">Than I realized I could avoid this pyramide of doom by doing it differently:</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">let listener: TCPListener</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">do {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>listener = try TCPListener("some address")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">} catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>fatallError("cannot create listener")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">let conn: TCPConn</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">do {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>conn = try listener.accept()</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">} catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>fatallError("cannot accept")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">// do some work and catch more errors</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">do {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>try conn.close()</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">} catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>do {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>try listener.close()</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>} catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>fatallError("cannot close listener")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>fatallError("cannot close connection")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">As you can see there is no need for the do block here. A single try-statement would do enough.</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class="">I could rewrite this example like this:</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">guard let listener = try TCPListener("some address") catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>fatallError("cannot create listener") // or return and try again later</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">guard let conn = try listener.accept() catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>fatallError("cannot accept")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">// do some work and catch more errors</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">do try conn.close() catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>do try listener.close() catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>fatallError("cannot close listener")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>fatallError("cannot close connection")</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div></div><br style="font-family: Helvetica, Arial; font-size: 13px; 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=""><div id="bloop_sign_1454700718218766080" class="bloop_sign" style="font-family: Helvetica, Arial; font-size: 13px; 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 style="font-family: helvetica, arial; font-size: 13px;" class="">-- <br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div><br style="font-family: Helvetica, Arial; font-size: 13px; 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=""><p class="airmail_on" style="font-family: Helvetica, Arial; font-size: 13px; 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;">Am 5. Februar 2016 bei 20:18:26, Adrian Zubarev (<a href="mailto:adrian.zubarev@devandartist.com" class="">adrian.zubarev@devandartist.com</a>) schrieb:</p><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><span class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""></div><div class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class="">+1 You are right Félix, it was only my own project that tempted me to return from each catch scope. </div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class="">But wouldn’t this confuse everyone?</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class="">Here is an example:</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><b class="">do let/var newInstance = try throwingFuncReturns() catch {</b></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><b class="">// can not fall through at all</b></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><b class="">}</b></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class="">There is no chance the compile can guarantee that `<b class="">newInstance</b>` was assigned with a value, except if `newInstance` is an optional type, so this code may not fall through like the '<b class="">guard</b>‘ mechanism.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><b class="">let newInstance: Type</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><b class="">do newInstance = try throwingFuncReturns() catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">// if not returned from here or the newInstance is not set here the compiler should raise an error</b></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><b class="">}</b></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class="">`<b class="">newInstance</b>` is only safe when throwing function returns without any errors or the instance was set inside the catch scope. This mimics the `if else` behavior. This can already be done with the existing `<b class="">do try catch</b>` mechanism.</div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">let x: SomeThing</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">if condition {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">x = foo()</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">} else {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">x = bar()</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">use(x)</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">do try throwingFunc() catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">// can fall through if needed (this means I can ignore the error or return/break)</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class="">Another way do this right now would look like this:</div><div id="bloop_customfont" style="margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">do {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">try throwingFunc() </b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">} catch _ { </b><b class="">} // will ignore the error</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class="">As you can see only the first example can not fall though after catching the error, so wouldn’t it be better to support both syntax variants?</div><div id="bloop_customfont" style="margin: 0px;" class=""><b class=""><br class=""></b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">guard let/var newInstance = try throwingFuncReturns() catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">// can not fall through</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div><div class=""><br class=""></div><div class=""><div id="bloop_customfont" style="margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">let newInstance: Type</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">do newInstance = try throwingFuncReturns() catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">// if not returned from here or the newInstance is not set here the compiler should raise an error</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div><div class=""><b class=""><br class=""></b></div><div class=""><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">do try throwingFunc() catch {</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">// can fall through if needed (this means I can ignore the error)</b></div><div id="bloop_customfont" style="margin: 0px;" class=""><b class="">}</b></div></div></div></div></div></div></div></div></div></div><br class=""><div id="bloop_sign_1454697774120125952" class="bloop_sign"><div style="font-family: helvetica, arial; font-size: 13px;" class="">-- <br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div><br class=""><p class="airmail_on">Am 5. Februar 2016 bei 19:40:46, Félix Cloutier (<a href="mailto:felixcca@yahoo.ca" class="">felixcca@yahoo.ca</a>) schrieb:</p><blockquote type="cite" class="clean_bq"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><span class="">Unless you're declaring a variable with a single-statement try, there's no reason to disallow fallthrough.<br class=""></span><div class=""><span class=""><br class="Apple-interchange-newline"><span class="" style="font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">Félix</span></span></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">Le 5 févr. 2016 à 13:28:58, Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;">Right now the error handling mechanism will fall through even if the error was handled inside the catch scope.</div><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;"><div class="" style="font-family: 'Source Code Pro'; font-size: 11px; margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">enum Error: ErrorType {</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">case SomeError</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">}</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class=""><br class=""></b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">func throwingFunc() throws {</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">throw Error.SomeError</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">}</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class=""><br class=""></b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">func throwingFuncReturns() throws -> Int {</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">return 0</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">}</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class=""><br class=""></b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">do { try throwingFunc() } catch {</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">/* do nothing */</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">}</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class=""><br class=""></b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">var num: Int</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">do { num = try throwingFuncReturns() } catch {</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">/* do nothing */</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">}</b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class=""><br class=""></b></font></div><div class="" style="margin: 0px; line-height: normal;"><font face="Helvetica" class=""><b class="">print("both fell through")</b></font></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px;"><br class=""></div></div><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;">To guarantee the safety of the execution from my point of view the catch body may not fall through (for single try statements), at least not by default.</div><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;"><br class=""></div><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;">I think it is fine to rename the proposed mechanism.</div><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;"><br class=""></div><div id="bloop_customfont" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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; margin: 0px;"><div class=""><b class="">do try throwingFunc() catch { </b></div><div class=""><b class="">/* handle error */ </b></div><div class=""><b class="">}</b></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">do try throwingFunc() catch _ { </b></div><div class=""><b class="">/* handle error */ </b></div><div class=""><b class="">}</b></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">do try throwingFunc() catch pattern { </b></div><div class=""><b class="">/* handle error */ </b></div><div class=""><b class="">}</b></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">do try throwingFunc() catch pattern { </b></div><div class=""><b class="">/* handle error */ </b></div><div class=""><b class="">}</b></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">do let newInstance = try throwingFuncReturns() catch </b><b class="">catch pattern </b><b class="">where condition</b><b class=""> { </b></div><div class=""><b class="">/* handle error */ </b></div><div class=""><b class="">}</b></div><div class=""><br class=""></div><div class=""><b class="">do var newMutableInstance = try throwingFuncReturns() catch pattern </b><b class="">where condition</b><b class=""> { </b></div><div class=""><b class="">/* handle error */ </b></div><div class=""><b class="">}</b></div><div class=""><b class=""><br class=""></b></div><div class=""><div class="">'<b class="">Where</b>' clause is significant for catching wider range of errors that might occur.</div></div></div><br class="" style="font-family: Helvetica, Arial; font-size: 13px; 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 id="bloop_sign_1454695983058411008" class="bloop_sign" style="font-family: Helvetica, Arial; font-size: 13px; 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="" style="font-family: helvetica, arial; font-size: 13px;">-- <br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div><br class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><p class="airmail_on" style="font-family: Helvetica, Arial; font-size: 13px; 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;">Am 5. Februar 2016 bei 19:05:12, Félix Cloutier (<a href="mailto:felixcca@yahoo.ca" class="">felixcca@yahoo.ca</a>) schrieb:</p><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; 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="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""></div><div class=""><span class="">We could do it without a new guard syntax if `do` didn't need a block statement.<br class=""></span><div class=""><span class=""><br class="Apple-interchange-newline"><span class="" style="font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">Félix</span></span></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">Le 5 févr. 2016 à 12:54:47, Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">Hello dear Swift community,</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">this proposal might seem like some new syntax sugar, but it also aims to escape the '<b class="">do { }</b>' scope from the '<b class="">do try catch</b>‘ mechanism while making the existing error handling more powerful.</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">Lets assume we have some sort of network type, which can throw a ton of different errors:</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">struct TCPListener {</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">init(address: String) throws { /* implement */ }</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class=""><br class=""></b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">func accept() throws -> TCPConn { /* implement */ }</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class=""><br class=""></b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">/* ... */</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">}</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">A way of implimentation might look like this:</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">let listener: TCPListener</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">do {</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">listener = try TCPListener("some valid address")</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class=""><br class=""></b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">// we could do more work here, but if we need to catch more</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">// errors we will result in a new PYRAMIDE OF DOOM</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">} catch {</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">fatalError()</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">}</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">At this point think about the comment inside the '<b class="">do { }</b>' scope. Such an application might result in a new pyramide of doom as we know from optional unwrapping before '<b class="">guard else</b>' mechanism was introduced.</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">let clientConn: TCPConn</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">do {</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">clientConn = try listener.accept() // save to call accept method</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">} catch {</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">fatalError()</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">} </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">As you can see this application might not need the extra 'do' scope at all, and if it does, the 'do try catch' is still there.</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">I propose a new<span class="Apple-converted-space"> </span><b class="">error handling mechanism</b><span class="Apple-converted-space"> </span>that mimics the solution for optional pyramide of doom, which adds a slightly better syntax and removes the unneeded/unused '<b class="">do { }</b>' scope (as for the example from above). Not only can this mechanism guarantee the execution of a throwing function without any errors (like a true guard condition) it also can assign returned values to a new constant/variable.</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">Introducing the '<b class="">guard try catch</b>' mechanism:</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">guard try throwingFunc() catch { </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">/* handle error */ </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">}</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class=""><br class=""></b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">guard try throwingFunc() catch _ { </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">/* handle error */ </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">}</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class=""><br class=""></b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">guard try throwingFunc() catch pattern { </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">/* handle error */ </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">}</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class=""><br class=""></b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">guard try throwingFunc() catch pattern where condition { </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">/* handle error */ </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">}</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class=""><br class=""></b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">guard let newInstance = try throwingFuncReturns() catch ... { </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">/* handle error */ </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">}</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">Where '<b class="">...</b>' represents the different combinations of possible patterns already showed in the first 4 examples.</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">We also might want the return type to be mutable.</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">guard var newMutableInstance = try throwingFuncReturns() catch ... { </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">/* handle error */ </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">}</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">This mechanism also makes the error handling more powerful, since it can catch more specific errors defined with '<b class="">where condition</b>'.</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">Lets rebuild the example from above with the new mechanism:</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">guard let listener = try TCPListener("some valid address") catch {</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">fatalError()</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">}</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class=""><br class=""></b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">guard let clientConn = try listener.accept() catch {</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">fatalError()</b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><b class="">} </b></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">One think that should be mentioned here is that the method call from the second '<b class="">guard</b>' is safe, because a '<b class="">guard</b>' body may not fall through.</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">Impact on existing codebase:<span class="Apple-converted-space"> </span><i class=""><u class="">None</u></i>, because the mechanism is new and does not break any existing code.</div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">I'm really curious about your opinions.</div><span class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">_______________________________________________</span><br class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><span class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">swift-evolution mailing list</span><br class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><a href="mailto:swift-evolution@swift.org" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">swift-evolution@swift.org</a><br class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></div></blockquote><span class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">_______________________________________________</span><br class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><span class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">swift-evolution mailing list</span><br class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><a href="mailto:swift-evolution@swift.org" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">swift-evolution@swift.org</a><br class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="" style="font-family: Helvetica, Arial; font-size: 13px; 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;">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></div></blockquote></div></div></span></blockquote><span style="font-family: Helvetica, Arial; font-size: 13px; 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><br style="font-family: Helvetica, Arial; font-size: 13px; 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, Arial; font-size: 13px; 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, Arial; font-size: 13px; 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, Arial; font-size: 13px; 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=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br style="font-family: Helvetica, Arial; font-size: 13px; 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, Arial; font-size: 13px; 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br class=""></body></html>