do/try/catch use the error handling mechanism, named exception.<br><br>I think we should use it carefully , it will results convoluted code and the risk of exception safe.<br><br><div class="gmail_quote"><div dir="ltr">Fernando Rodríguez &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;于2016年8月6日 周六07:50写道:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I do a lot of training and one of the features of Swift that seems more confusing to students (and myself) is error handling. There are too many ways of doing it, and none seems satisfactory.</div><div><br></div><div>Let&#39;s take for example an initializer. There are 2 different ways of handling errors within an init:</div><div><br></div><div>a) Old School: return nil. This was very simple in Objective C, because the uncommon case of an error could be easily ignored...until everything crashed.</div><div><br></div><div>In Swift it&#39;s not easy (nor advisable IMHO) to completely ignore the possibility of an error. Besides, it has 2 complications.</div><div><br></div><div>First of all, you return an Optional, and Optionals have a tendency to go viral. Suddenly, all your code has to deal with optionals.</div><div><br></div><div>Secondly, you have no information about the error itself.</div><div><br></div><div>b) do/try/catch</div><div><br></div><div>This allows you to have information about the error, but also causes the newly created object to be &quot;trapped&quot; inside a do block.</div><div><br></div><div>Are there any plans to address this situation? I believe there should be a single, obvious and convenient way of handling errors in the language.</div><div><br></div><div>What do you guys think?</div><div><br></div><div><br clear="all"><div><br></div>-- <br><div data-smartmail="gmail_signature"><div dir="ltr"><div><br></div><div><div dir="ltr" style="font-family:arial;font-size:small;line-height:normal"><table width="400" border="0" cellspacing="0" cellpadding="0" style="color:rgb(0,0,0);font-family:Times"><tbody><tr><td width="150" rowspan="3" align="center" valign="top"><br><table border="0" cellspacing="0" cellpadding="0" style="font-family:Times;border-collapse:collapse;border:none"><tbody><tr><td width="112" valign="top" style="width:111.75pt;padding:0cm 5.4pt"><p></p><p><b><span lang="ES" style="font-family:Helvetica;color:rgb(213,117,7)"><a href="http://keepcoding.io/es/" style="color:rgb(17,85,204)" target="_blank"><img src="https://docs.google.com/uc?export=download&amp;id=0Bzx0v_J9FCNPNllTZ19uM1hxbXc&amp;revid=0Bzx0v_J9FCNPb2trZU1BWXFabFdkUngvd0Nmd2Q4ZTdWaHNNPQ" width="200" height="138"></a></span></b></p></td></tr></tbody></table><br><br></td><td style="font-family:Helvetica,Arial,sans-serif;font-size:12px;color:rgb(100,100,100)"><p style="margin:0px;font-size:14px;font-family:Helvetica;color:rgb(64,64,64)"><b>Fernando Rodríguez</b></p><p style="margin:0px;font-family:Helvetica">m. +34 610 965 332</p><p style="margin:0px;font-family:Helvetica">t. +34 91 629 57 61</p><p style="margin:0px;font-family:Helvetica"><a href="mailto:fernando@agbo.biz" target="_blank">fernando@k</a><a href="http://eepcoding.io" target="_blank">eepcoding.io</a></p><p style="margin:0px;font-family:Helvetica"><span><img alt="pastedGraphic.png"></span><span style="font-size:16px;font-family:Arial;color:rgb(35,35,35)"> </span><img alt="pastedGraphic_1.png"><span style="font-size:16px;font-family:Arial;color:rgb(35,35,35)"> </span><img alt="pastedGraphic_2.png"></p><p style="margin:0px;font-size:10px;font-family:Helvetica;color:rgb(64,64,64)"><b>KeepCoding.io</b></p><p style="margin:0px;font-size:10px;font-family:Helvetica;color:rgb(64,64,64)">2120 University Avenue, Berkeley, CA</p><p style="margin:0px;font-size:10px;font-family:Helvetica;min-height:12px"><br></p><p style="margin:0px;font-size:10px;font-family:Helvetica">Avda. Fuencarral, 44, Ed. 8, Loft 30</p><p style="margin:0px;font-size:10px;font-family:Helvetica">28108 Alcobendas (Madrid) Spain</p><div><br></div></td></tr></tbody></table></div><div style="color:rgb(0,0,0);font-family:Helvetica"><div dir="ltr" style="color:rgb(34,34,34);font-family:arial;font-size:small;line-height:normal"><table width="75%" border="0" cellspacing="0" cellpadding="0" style="color:rgb(0,0,0);font-family:Times"><tbody><tr><td style="font-family:Verdana;font-size:7px;color:rgb(153,153,153);padding-top:10px;text-align:justify"><br></td></tr></tbody></table></div></div></div></div></div>
</div></div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>