10 lines
178 B
Text
10 lines
178 B
Text
func Integer.Add(x) {
|
|
throw @NegativesNotAllowed(x) when x < 0
|
|
this + x
|
|
}
|
|
|
|
try {
|
|
12.Add(-5)
|
|
} catch {
|
|
@NegativesNotAllowed(x) => print("Negative number: \(x)")
|
|
}
|