Okay, the OP talked about wanting to know about both stack overflow and arithmetic overflow, as well as their corresponding underflow. Here goes....
- Arithmetic overflow happens when a number gets too big to fit in its value type. For example, an
int
holds values between -231 and 231-1, inclusive. If your number goes over these limits, an overflow occurs, and the number "wraps around". These do not cause an exception to be generated in Java.
- Arithmetic underflow happens when a floating point number gets too small to distinguish very well from zero (the precision of the number got truncated). In Java, these do not cause an exception either.
- Stack overflow happens when you call a function, that calls another function, that then calls another, then another...and the function call stack gets too deep. You get a
StackOverflowError
when that happens.
- Stack underflow doesn't happen in Java. Its runtime system is supposed to prevent that sort of stuff from happening.
To answer the OP's other question (see comments), when you overstep the boundaries of an array, an IndexOutOfBoundsException
is issued.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…