Results 1 to 2 of 2
  1. #1
    vendetta is offline Member
    Join Date
    Jan 2010
    Rep Power

    Default 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?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    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

  1. pls expalin me with any proper example
    By javastuden in forum New To Java
    Replies: 1
    Last Post: 11-05-2009, 10:35 AM
  2. Replies: 1
    Last Post: 08-07-2009, 09:37 PM
  3. Any suggestions on what i need tp change for a proper output.
    By PureAwesomeness in forum New To Java
    Replies: 10
    Last Post: 02-24-2009, 12:46 AM
  4. Need help. Method won't returning proper value..
    By zlwilly in forum New To Java
    Replies: 2
    Last Post: 12-02-2008, 09:44 PM
  5. Replies: 4
    Last Post: 07-31-2008, 01:43 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