This is one of the two action listeners I have for two text fields. The exceptions to ensure the proper datatypes used is working. And the exception to make sure that int pos is within the array's range is working. The problem I am having is getting the out of bounds exception to work without calling either of the other two catches. If any more info is required don't hesitate to ask. TY
class ActListener1 implements ActionListener {
public void actionPerformed( ActionEvent e) {
int pos = 0;
String strPos = input1.getText();
String strValue = input2.getText();
try{
pos = Integer.parseInt( strPos );
}catch(Exception ex1){
String output1 = "Incorrect datatype entered for textfield 1\n" +
"Occured after pressing enter in the 1st textfield\n" +
"Enter appropriate datatype\n" + ex1.toString();
JOptionPane.showMessageDialog(null, output1);
}
try {
if (pos < MIN_INDEX || pos > MAX_INDEX) {
throw new Exception("Index out of bounds");
}
} catch (Exception ob) {
String output2 = "Index is out of bounds\n" +
"Exception occured after pressing enter in the first textfield\n" +
"Re-enter a selection in the range of " + MIN_INDEX + " - " + MAX_INDEX;
ob.toString();
JOptionPane.showMessageDialog(null, output2);
}
try{
double value = Double.parseDouble( strValue );
numArray.insertNumberAtPos( value, pos );
}catch(Exception ex2){
String output2 = "Incorrect datatype entered for textfield 2\n" +
"Occured after pressing enter in the 1st textfield\n" +
"Enter appropriate datatype\n" + ex2.toString();
JOptionPane.showMessageDialog(null, output2);
}
// Display list and results
TDisplay.setText(createListStr());
}
}