I am trying to get a hold of overflow and underflow exceptions in java, but couldn’t get any nice tutorial. Specifically I wish to learn
- How are they different from each other?
- What are the subclasses of these exceptions?
- In which scenario they are thrown?
- Which of them can be handled and how?
- What are the best practice related to them?
Any link to useful tutorial will do
Okay, the OP talked about wanting to know about both stack overflow and arithmetic overflow, as well as their corresponding underflow. Here goes….
intholds 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.StackOverflowErrorwhen that happens.To answer the OP’s other question (see comments), when you overstep the boundaries of an array, an
IndexOutOfBoundsExceptionis issued.