[swift-users] Parameter Validation

David Hart david at wittywings.fr
Mon Dec 7 11:03:15 CST 2015

But then you can't unit-test that the function fails on those parameters. To look at a counter-argument, both C# and Java would throw exceptions for parameter validation.

> On 07 Dec 2015, at 17:30, Jens Alfke <jens at mooseyard.com> wrote:
>> On Dec 6, 2015, at 11:49 PM, David Hart via swift-users <swift-users at swift.org> wrote:
>> I’m looking at the special case of library code. If I surface an API in a library, it’s the library user who will call this function. Would you regard this as an assert or throws scenario?
> Assert. It’s not library vs. non-library, it’s a question of bug vs. legitimate runtime error. Passing an invalid parameter value is a bug.
> For example, Foundation is a library, and passing an invalid parameter to a Foundation method triggers an assertion failure.
> —Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151207/6aff2836/attachment.html>

More information about the swift-users mailing list