Results 1 to 2 of 2
  1. #1
    susan is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default 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

  2. #2
    cachi is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

Similar Threads

  1. Need help on Exception
    By Deon in forum New To Java
    Replies: 7
    Last Post: 02-11-2010, 05:46 PM
  2. Where does the exception go?
    By aytidaalkuhs in forum New To Java
    Replies: 3
    Last Post: 04-07-2008, 02:24 PM
  3. exception
    By Oktam in forum New To Java
    Replies: 2
    Last Post: 03-23-2008, 07:01 PM
  4. Replies: 1
    Last Post: 03-08-2008, 06:41 PM
  5. Exception
    By Camden in forum New To Java
    Replies: 2
    Last Post: 11-26-2007, 11:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •