<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=""><br class=""></div><div class=""><blockquote type="cite" style="font-family: Alegreya-Regular; font-size: 15px; font-style: normal; font-variant-caps: 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="">Do you have an imagined use for throwing getters?<br class=""></blockquote></div></blockquote></div><br class=""><div class="">The project I work on — <a href="https://github.com/couchbase/couchbase-lite-ios" class="">a database engine</a> — has an API with a lot of things that are conceptually properties, but whose accessors can fail because they may have to read or write persistent storage. Some examples are Database.documentCount and Document.currentRevision.</div><div class=""><br class=""></div><div class="">In the current (Objective-C) API, some of these are exposed as methods that use the standard Cocoa NSError-returning pattern, while some that are very unlikely to fail are exposed as actual properties; the implementations either return a distinct failure value like nil, or just a default value like 0. I’m not saying this is great, but it’s a tradeoff between correctness and ease of use where we’ve sometimes leaned toward ease of use.</div><div class=""><br class=""></div><div class="">Failable property accessors would be a big help here, letting us have an expressive API where properties are properties, while not losing the ability to do proper error handling.</div><div class=""><br class=""></div><div class="">The same applies to subscripts, btw. Since our data stores are key-value collections it’s convenient to be able to subscript a database by key to get a value. Of course this has the potential to fail due to file corruption, disk I/O errors, etc. </div><div class=""><br class=""></div><div class="">As another example, I’ve done some experimental work in the past on incremental JSON parsing; if using such a library, errors are not necessarily discovered up front, so it’s possible for accessing an item in a JSON array or dictionary to fail with a parse error. (Yes, you could syntax-check ahead of time, but since the major purpose of the incremental parsing is speed, that would be self-defeating.)</div><div class=""><br class=""></div><div class="">—Jens</div></body></html>