[swift-users] "business applications market" flame

Rob Mayoff mayoff at dqd.com
Fri Jan 8 16:28:56 CST 2016


Why are you even using throw and try-bang here? It looks like, instead of
throw, you should be using preconditionFailure: “Use this function to stop
the program when control flow can only reach the call if your API was
improperly used.”

https://developer.apple.com/library/ios/documentation/Swift/Reference/Swift_StandardLibrary_Functions/index.html#//apple_ref/swift/func/s:FSs19preconditionFailureFTKT_SS4fileVSs12StaticString4lineSu_T_


On Thu, Jan 7, 2016 at 4:33 PM, Don Wills via swift-users <
swift-users at swift.org> wrote:

>
> *func add(p1: String, _ p2 Any) {*
> *    try! addWithThrows(p1, p2)*
> *}*
>
> *private func addWithThrows(p1: String, _ p2 Any) throws {*
> *    // code that handles many types for p2, followed by return for each
> of the valid types*
> *    throw Exception("Invalid type")  /* for those types not supported
> which is a programmer error */*
> *}*
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160108/52d43eb8/attachment.html>


More information about the swift-users mailing list