> On Aug 5, 2016, at 7:16 PM, Erica Sadun via swift-evolution
> <[email protected]> wrote:
>
> Would it kill to allow:
>
> let err = NSError()
> err.localizedDescription = "bad things happen"
> throw err
>
> or even
>
> throw NSError("Bad things happen")
You can make something that can do that fairly easily:
struct TextualError: LocalizedError {
var errorString: String
init() {
self.init("")
}
init(_ string: String) {
self.errorString = string
}
var failureReason: String? {
return self.errorString
}
}
Then, you can just:
throw TextualError("Must Sterilize!”)
Or:
var error = TextualError()
error.failureReason = "Must Sterilize!”
throw error
Charles
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution