Results 1 to 2 of 2
  1. #1
    Cutter is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default Multiple Exceptions with Array

    Good Afternoon,

    I would like to learn, and need direction if possible please.

    Here is my challenge.

    I want to pull from an Array of multiple "error messages" when the user inputs the incorrect data.

    This is my array:

    Java Code:
    import java.util.*;
    public class OrderMessages 
    {
     public static void main(String[] args)
      {
    
      String[] errorMessages = new String[7];
      errorMessages[0] = "The Item is not numeric";
      errorMessages[1] = "The quantity is not numeric";
      errorMessages[2] = "The item number is too low";
      errorMessages[3] = "The item number is to high";
      errorMessages[4] = "The quantity ordered is too low";
      errorMessages[5] = "The quantity ordered is too high";
      errorMessages[6] = "The item number is not valid";
      
      
       {
       System.out.println(errorMessages[0]);
      }
      }
      }
    Then I would create a class that displays one of the messages(easy enough I think ).

    Then an Applet.
    The user then inputs an item number (ie 1) then a quantity.

    I then assign a price to it (i.e $0.89ea)., and caluculate the math..etc...

    If he/she inputs the incorrect info as per my exception array, then the error is displayed.
    I'm assuming the try and catch with multiple catches.
    all wrapped in an Applet.

    Trying to find the correct "starting point" has been my challenge.

    I've tries a couple different approaches on paper so far, but they all seem to go nowhere.

    Now, I'm more confused than ever.

    yes, I am a mature student, and I am learning for fun.

    if I am not using proper terms etc...please let me know..

    Thank you in advance

    Cutter

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,342
    Blog Entries
    7
    Rep Power
    20

    Default

    Don't use arrays for that purpose although you think they look neat and organised for the purpose; arrays are so Fortranesque; use exceptions instead: throw an exception that contains the appropriate message right where you detect the error. An IllegalArgumentException would do fine.

    kind regards,

    Jos

Similar Threads

  1. Exceptions
    By hedonist in forum New To Java
    Replies: 10
    Last Post: 09-08-2009, 08:38 AM
  2. Exceptions in thread
    By Goodwater in forum New To Java
    Replies: 4
    Last Post: 03-16-2009, 03:00 AM
  3. Need Help With Exceptions
    By maggie_2 in forum New To Java
    Replies: 5
    Last Post: 12-15-2008, 07:12 PM
  4. Can I store multiple objects in an array
    By lareauk in forum New To Java
    Replies: 9
    Last Post: 05-29-2008, 03:57 AM
  5. Question on Exceptions
    By yelllow4u in forum New To Java
    Replies: 6
    Last Post: 07-27-2007, 01:41 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
  •