• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

I have a java code that is not preforming what i expect to, i am very new to java.

I have the below code and I needed to add a try catch to insure proper data, the below doesn't work at all. It prompts for the blower value but if I type in an improper value it still will not "catch" the error?  Please help if possible I am very new to java.

      String test = " ";
                boolean badInput = true;
                    if(race.getClass()== Hotrod.class)
                          Hotrod h =(Hotrod)race;
                            //test = (getInput("Blower equipped: Y/N"));
                            if (test.equalsIgnoreCase("y"))
                          }// end if
                          else if (test.equalsIgnoreCase("n"))
                          } //end else if
                                        test = (getInput("Blower equipped: Y/N"));
                                        if (!test.equalsIgnoreCase("y")|| !test.equalsIgnoreCase("n"))
                                        badInput = false;
                                  catch (Exception ex)
                                        JOptionPane.showMessageDialog(null,test  + "Please enter the proper value","Error",JOptionPane.PLAIN_MESSAGE);
                             } while(badInput);
                             }//end else
                    } //end if(race.getClass()== Hotrod.class)
1 Solution
In order for an exception to be caught, the exception first needs to be thrown.
In this case, there seems to be no need to use the exception mechanism when you can just check  badInput.
stevendeveloperAuthor Commented:
I understand I will alter the code maybe with do while loop?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now