Results 1 to 2 of 2
- 01-16-2010, 07:19 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 31
- Rep Power
- 0
proper use of IllegalArgumentException
I am making a pseudorandom number generator for my first Java project. It works by having variables multiply by each other and then using the modulus operator. The output from that method is recorded by what range the number was in. That number is then used to replace one of the original variable values that will output a new number after the method is used again. The process repeats many times putting the numbers in 10 groups to see how random the variable selection was.
If a negative number is used on one of the variables, there is not a mathematical error, but it puts all the random numbers in just one of the 10 groups thus making the method useless. Is programmer discretion a case for IllegalArgumentException because he sees unfavorable results by using a negative value, or are throws only used when it will make an error in the program such as dividing by zero?
- 01-16-2010, 07:43 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
It seems reasonable to throw an exception if the argument is outside the documented range. You can see the uses of the exception in the standard API by looking in the "uses" documentation. There aren't all that many (it slightly surprised me). Many classes like Rectangle allow all sorts of values beyond those whose meaning is obvious.
Similar Threads
-
pls expalin me with any proper example
By javastuden in forum New To JavaReplies: 1Last Post: 11-05-2009, 10:35 AM -
Sending SMS to other mobile geting exception as java.lang.IllegalArgumentException
By maruffaiz in forum CLDC and MIDPReplies: 1Last Post: 08-07-2009, 09:37 PM -
Any suggestions on what i need tp change for a proper output.
By PureAwesomeness in forum New To JavaReplies: 10Last Post: 02-24-2009, 12:46 AM -
Need help. Method won't returning proper value..
By zlwilly in forum New To JavaReplies: 2Last Post: 12-02-2008, 09:44 PM -
Java Script comes with No proper error message in the Alert box in Struts.
By anandguna in forum Advanced JavaReplies: 4Last Post: 07-31-2008, 01:43 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks