RosettaCodeData/Task/Exceptions/Dyalect/exceptions.dyalect

11 lines
178 B
Plaintext

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