[swift-users] Parameter Validation
jens at mooseyard.com
Sun Dec 6 23:33:54 CST 2015
> On Dec 6, 2015, at 12:49 PM, David Hart via swift-users <swift-users at swift.org> wrote:
> When writing library code, what method of parameter validation would be suggested?
Definitely assert. Assert is for illegal calls, i.e. programmer errors, while errors (throw) are for valid runtime error conditions.
> * Disabled in release
I believe there is a compiler flag to control this, if you want them enabled in the release.
> * Not unit-testable
Well, you can’t create tests for rejection of illegal parameters. Which doesn’t seem like a huge loss to me. It would be nice to be able to do this, though. Maybe through some mechanism for catching / recovering from the otherwise-fatal exception triggered by an assert failure?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users