Distinguish between exception and runtime error. An exception is thrown, and can be detected. Runtime error stops your program on their tracks. Adding and receiving overflow - a run-time error, plain and simple. Nothing to catch.
Type operator point &+ lies in the fact that it is not a fault and does not reflect a problem. That's the whole point.
If you think you can overflow, and want to know if you have made, use static methods such as addWithOverflow . It returns a tuple consisting of the result, and Bool, indicating the presence of an overflow.
var x: Int8 = 100 let result = x &+ x // -56 x = 100 let result2 = Int8.addWithOverflow(x,x) // (-56, true) -56 var x: Int8 = 100 let result = x &+ x // -56 x = 100 let result2 = Int8.addWithOverflow(x,x) // (-56, true)
source share