Page 4 of 4 FirstFirst ... 234
Results 61 to 63 of 63
Like Tree1Likes

Thread: try/catch Help please

  1. #61
    Goodoleboy58 is offline Member
    Join Date
    May 2012
    Posts
    34
    Rep Power
    0

    Default Re: try/catch Help please

    Man, you have no idea how much it means to me that you stayed up this long to help me out. I do appreciate your time. I hope one day when I get to be a pro at this I can help someone out in a similar situation.

  2. #62
    brynpttrsn is offline Member
    Join Date
    Sep 2011
    Posts
    59
    Rep Power
    0

    Default Re: try/catch Help please

    Lol good... now to be nitpicky... code formatting *cringes*
    And change
    Java Code:
                           case 2:
    	                   JOptionPane.showMessageDialog(null, colorinvalidEntry);
    
    
    	 					if(!colorcustomerReturn.matches("[a-zA-Z]*"))
    
    	 					{
    	     					throw new Exception();
    	 					}
    
    	 					else
    
    	    					JOptionPane.showMessageDialog(null, "Please enter a Valid Color");
    to:
    Java Code:
                                               case 2:
    	 					if(!colorcustomerReturn.matches("[a-zA-Z]*"))
    
    	 					{
    	     					throw new Exception();
    	 					}
    
    	 					else
    
    	    					JOptionPane.showMessageDialog(null, colorinvalidEntry);
    Just so you dont get the double error prompt.

    Lol no problem.
    Last edited by brynpttrsn; 05-07-2012 at 10:24 AM.

  3. #63
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,776
    Blog Entries
    7
    Rep Power
    21

    Default Re: try/catch Help please

    I'm sorry for saying so but the 'solutions' (mind the quotes) in this thread are a total mess; have a look at this way of doing it:

    Java Code:
    import java.util.HashSet;
    import java.util.Set;
    
    
    public class T {     
    	public static void main (String[] args) {
    		Set<String> colors= new HashSet<String>() {{
    			add("blue");
    			add("yellow");
    			add("green");
    		}};
    		
    		System.out.println("green --> "+colors.contains("green"));
    		System.out.println("red   --> "+colors.contains("red"));
    	}
    }
    kind regards,

    Jos
    brynpttrsn likes this.
    cenosillicaphobia: the fear for an empty beer glass

Page 4 of 4 FirstFirst ... 234

Similar Threads

  1. Try... Catch?
    By Callofdudey in forum New To Java
    Replies: 3
    Last Post: 10-06-2011, 10:29 PM
  2. try and catch
    By Bimz in forum New To Java
    Replies: 1
    Last Post: 09-26-2011, 10:44 AM
  3. how to catch two exceptions in one catch()?
    By arnab321 in forum New To Java
    Replies: 1
    Last Post: 11-06-2008, 11:54 AM
  4. try catch...
    By MarkWilson in forum New To Java
    Replies: 8
    Last Post: 06-27-2008, 06:39 PM
  5. Use try and catch
    By zoe in forum New To Java
    Replies: 2
    Last Post: 07-25-2007, 08: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
  •