Integer overflow is actually quite useful in computing. If he threw exceptions, many smart algorithms would suddenly break down or become impractical. For example, everything related to fixed-point arithmetic suddenly throws exceptions.
The fact is that overflow is usually not a problem, because we limit our programs to prevent it (if this leads to problems). In other cases, we develop programs that specifically use it.
Do not think of overflow as "a value that exceeds its maximum size." This is technically impossible. The bits simply wrap around and remain within these data types.
If you need to check for overflow and want to throw exceptions, you can do this:
byte b = 127; byte oldb = b; b++; if( b < oldb ) {
Do not be afraid of your whole limits. Learn to understand and work with them.
source share