<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">+1 to this. &nbsp;Subscripts should also be able to throw and currently cannot.<div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 9:08 PM, Nikolai Vazquez via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">One of the aspects of Swift that I like is computed properties for structures and classes. It allows for adding logic when obtaining values or for having the returned value be dependent on another.</div><div class=""><br class=""></div><div class="">As of the `ErrorType` protocol introduction in Swift 2, we can throw errors when it comes to functions and initializers. However, this does not apply to getters and setters.</div><div class=""><div class=""><div class=""><br class=""></div><div class=""><div class="">```swift</div><div class="">struct File&lt;Data&gt; {</div><div class="">&nbsp; &nbsp; var contents: Data {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; get throws { ... }</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; set throws { ... }</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div><div class="">```</div></div></div><div class=""><br class=""></div><div class="">A better example would be getting and setting the current working directory of the process:</div><div class=""><br class=""></div><div class=""><div class="">```swift</div><div class="">import Foundation</div><div class=""><br class=""></div><div class="">extension Process {</div><div class="">&nbsp; &nbsp; static var workingDirectory: String {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; get {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let fileManager = NSFileManager.defaultManager()</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return fileManager.currentDirectoryPath</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; set throws {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let fileManager = NSFileManager.defaultManager()</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; guard fileManager.changeCurrentDirectoryPath(newValue) else {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw Error("...")</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">```</div></div><div class=""><br class=""></div><div class=""><br class=""></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAfl-2BiqO0EPyHMi667csqGqnS8zsvC7hbTRcL7iqVxqOu9cb5ugMs9I3ip1C1qB2VCU4zyE0-2BusyW7-2B5YjqXTkIOPkyK7hYPEZWwLg1cnt-2BMhGFgwqbARFu1Sb3jUC6K6X5teb8G88uQTbm25lS3XU6ssgzLoO3vj6xmHfA-2BITsySoiYEEpwkTjJ5WUTCC9C5cE-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<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>