<font size=2 face="sans-serif">Classification: Public
<br>
<br>
Hello,</font>
<br>
<br><font size=2 face="sans-serif">I stumbled upon the exception handling
and the quite practical guard keyword for early-exiting a function.</font>
<br><font size=2 face="sans-serif">Unfortunately, the try? discards an
exception, if there is one.</font>
<br>
<br><font size=2 face="sans-serif">What I am interested in is to use the
shorter guard-style instead of the lengthy do/try/catch-approach, example
follows:</font>
<br>
<br><font size=2 face="sans-serif">Current situation is (example #1):</font>
<br><tt><font size=2>let smth: AnyObject?<br>
do {<br>
smth = try myThrowingFunc()<br>
} catch let error {<br>
print(error) // here I can access the exception, but this
code is quite big and not very intuitive, and the result will always be
an optional<br>
return<br>
}</font></tt>
<br>
<br><font size=2 face="sans-serif">I would like to use it like this(example
#2):</font>
<br><tt><font size=2>guard let smth = try? myThrowingFunc() else {<br>
print(error) // in swift 2.2 the exception is discarded,
so no access possible, but this code is much cleaner<br>
return<br>
}</font></tt>
<br>
<br><font size=2 face="sans-serif">Advantages are better readability because
of shorter code, and to avoid the optionals from ex.#1 and therefore alot
of ! and ? afterwards. In ex#2 I either have the smth constant, or the
function stops and returns. In ex#1, I will have an optional with a value,
which again needs a few additional steps to unwrap and use.</font>
<br>
<br><font size=2 face="sans-serif">So I would love the ability to access
exceptions (maybe with a standard variable name) inside a guard-clause</font>
<br>
<br><font size=2 face="sans-serif">I have created a question on stackoverflow
here: </font><a href=http://stackoverflow.com/questions/35776383><font size=2 face="sans-serif">http://stackoverflow.com/questions/35776383</font></a>
<br><font size=2 face="sans-serif">But have answered that already myself.
I would love to get some feedback from you guys, maybe you have some other
tips for me.</font>
<br>
<br>
<br><font size=2 face="sans-serif">Kind regards,<br>
Matis Schotte<br>
</font><font size=2 color=#d2d2d2 face="sans-serif"><br>
____________________________________________________</font><font size=3><br>
<br>
</font><img src=cid:_1_342B08D432057A9C005D39B3C1257F6B><font size=3><br>
</font><font size=2 face="Arial"><br>
Matis Schotte</font><font size=1 face="Arial"><br>
Mobile Solutions | Software Engineer<br>
<br>
Deutsche Bank AG<br>
Theodor-Heuss-Allee 72, 60486 Frankfurt am Main, Germany<br>
Email </font><a href=mailto:matis.schotte@db.com><font size=1 color=#0000a1 face="Arial"><u>matis.schotte@db.com</u></font></a>
<br><font size=3><br>
</font><img src=cid:_1_342B10C8342B0DE0005D39B3C1257F6B>
<br><font size=2 face="sans-serif"><br>
</font><P><SPAN style="font-size: smaller;"><SPAN style="font-family: Arial;">-- </SPAN></SPAN></P><P><SPAN style="font-size: smaller;"><SPAN style="font-family: Arial;">Informationen (einschließlich Pflichtangaben) zu einzelnen, innerhalb der EU tätigen Gesellschaften und Zweigniederlassungen des Konzerns Deutsche Bank finden Sie unter </SPAN></SPAN><A href="http://www.deutsche-bank.de/de/content/pflichtangaben.htm"><SPAN style="font-size: smaller;"><SPAN style="font-family: Arial;">http://www.deutsche-bank.de/de/content/pflichtangaben.htm</SPAN></SPAN></A><SPAN style="font-size: smaller;"><SPAN style="font-family: Arial;">. Diese E-Mail enthält vertrauliche und/ oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser E-Mail ist nicht gestattet.</SPAN></SPAN></P><P><SPAN style="font-size: smaller;"><SPAN style="font-family: Arial;">Please refer to </SPAN></SPAN><A href="http://www.db.com/en/content/eu_disclosures.htm"><SPAN style="font-size: smaller;"><SPAN style="font-family: Arial;">http://www.db.com/en/content/eu_disclosures.htm</SPAN></SPAN></A><SPAN style="font-size: smaller;"><SPAN style="font-family: Arial;"> for information (including mandatory corporate particulars) on selected Deutsche Bank branches and group companies registered or incorporated in the European Union. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and delete this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.</SPAN></SPAN></P>