<div dir="ltr">I suggest using an enum to represent success and failure. It's usually referred to as `Result`. It might seem weird for the closure that you presented as an example, since it would be Result<Void>, but it properly captures the possibility of having thrown.<div><br></div><div>``` swift</div>enum UselessError : Swift.Error {<br> case somethingBadHappened<br>}<br><br><br>enum Result<T> {<br> case success(T)<br> case failure(Swift.Error)<br><br> init(throwingClosure: (Void) throws -> T) {<br> do {<br> self = try .success(throwingClosure())<br> } catch {<br> self = .failure(error)<br> }<br> }<br>}<div><br>func burnItDown() throws -> Void {<br> throw UselessError.somethingBadHappened<br>}<br><br>Result(throwingClosure: burnItDown)<div>```</div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 9, 2017 at 10:28 PM, Jacob Bandes-Storch via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Moving to swift-users list.<div class="gmail_extra"><br clear="all"><div><div class="m_7830697524789680540m_9079363423569745951gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>No, there's no way to do this today. The point of rethrows is that within one call site, "f(block)" can be treated as throwing if the block throws, or not throwing if the block doesn't throw. In your example, once the FStore object is constructed, the information about the original passed-in function is lost, so the caller has no way to know whether call() can throw or not.</div><div><br></div><div>If this *were* possible, the information would somehow need to be encoded in the type system when creating FStore(f: block). That would require something like dependent typing, or generic-param-based-rethrows, e.g.</div><div><br></div><div>struct FStore<T: () throws -> Void> { // made-up syntax</div><div> let f: T</div><div> func call() rethrows(T) { try f() } // throws-ness of this function depends on throws-ness of T</div><div>}</div></div></div></div>
<br><div class="gmail_quote"><div><div class="h5">On Mon, Jan 9, 2017 at 9:21 PM, Howard Lovatt via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi,<div><br></div><div>If I have an escaping function that I store and then call, I need to declare the calling function as throwing, not rethrowing. EG:</div><div>
<p class="m_7830697524789680540m_9079363423569745951m_-6115875790740195702gmail-p1"><span class="m_7830697524789680540m_9079363423569745951m_-6115875790740195702gmail-s1"> </span>struct FStore {<br> let f: () throws -> Void<br> init(f: @escaping () throws -> Void) { self.f = f }<br> func call() throws { try f() } // Can't put rethrows here - have to use throws<br> }</p></div><div>Is there a better solution?</div><div><br></div><div>Thanks for any suggestions,</div><div><br clear="all"><div><div class="m_7830697524789680540m_9079363423569745951m_-6115875790740195702gmail_signature"> -- Howard.<br></div></div>
</div></div>
<br></div></div>______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div>
<br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>