-
Outofbounds exception
I just noticed when coding a new class that the byte 'wraps' itself when typecasted:
byte num = (byte)130
results in
num = -126
So, I can see what is happening here, obviously its taking the 128 as being -128 and adding the difference.
Problem is, I'm attempting to code a class that allows me to check a range between 0 and 127, and catch any exceptions thrown if out of the range from -128 - 127.
However, I cannot catch any exceptions from this since it always rolls it back to -128 and that falls within the range.
Anyway, for my actual question: Is this the normal behaviour of java? I could swear that when I first started that programs threw an outofbounds exception of some sorts when it fell out of the -128 - 127 range, and that it didn't wrap the values.
Thanks
-
Perhaps you were using the Byte wrapper class instead?
http://java.sun.com/j2se/1.4.2/docs/...lang/Byte.html
Greetings.