Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-13-2007, 07:31 PM
Member
 
Join Date: Jul 2007
Posts: 44
susan is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 06:13 AM
Member
 
Join Date: Jul 2007
Posts: 40
cachi is on a distinguished road
Perhaps you were using the Byte wrapper class instead?
http://java.sun.com/j2se/1.4.2/docs/...lang/Byte.html

Greetings.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where does the exception go? aytidaalkuhs New To Java 3 04-07-2008 04:24 PM
exception Oktam New To Java 2 03-23-2008 09:01 PM
Trouble with factory method - unhandled exception type Exception desmond5 New To Java 1 03-08-2008 08:41 PM
Need help on Exception Deon New To Java 5 01-26-2008 10:27 AM
Exception Camden New To Java 2 11-27-2007 01:50 AM


All times are GMT +3. The time now is 11:59 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org