Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Ira Adams   on Oct 16 In Java Category.

  
Question Answered By: Maliha Malik   on Oct 16

The best way to handle this is not to use a try/catch block, but to
get the text from the JoptionPane and determine if it is null BEFORE
you parse the int... Otherwise you will have to put  a try/catch on
each call.

You could also create an array of int[] and loop through the

for(int i=0; i<numberOfIntegers; i++){
try{
int[i] = Integer.parseInt(JOptionPane.showInputDialog("type the
number"));
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "you have to make an entry");}
i = i-1;
}
}

You could have an array of Strings which would give you a different
message for each loop... etc etc...

That way, you don't have to have 1000's of try/catches, and you
ALWAYS know which input failed.

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Catching Exceptions Or get search suggestion and latest updates.


Tagged: