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: Holly Brown   on Oct 16

Sometimes your code  may warrant lots of try/catch blocks. But when
that does happen, you should re-examine your design to see if perhaps
you are coding procedurally instead of objectly (is that a word?)

In this case, you might try the exception's toString() method to see
if it will give you enough detail to tease out the line  number. That
will work for a school project.

In this case, you might set up a loop:
While(...) {
try {
for (int i=1;i<4;i++) {
intV = Integer.parseInt(JOptionPane.showInputDialog("type the " + i
+ " number"));}
catch  (Exception e) { examine value of i to determine which one
failed}
} // end while

a19859 suggests using a boolean variable. You could add that advice
into this advice and have strong control over the inputs.

There are several other ways to handle this issue, but the general
idea is to merge your design with suggestions to arrive at a solution.

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: