Basic error handling - no row selected when deleting a row
I've been trying a few things, and was wondering if anybody had any advice or knew some websites that has some information on error handling. I need to refresh my memory a little. I have been attempting to make it work by using if-else statements, but I will probably need to use try-catch ones.
Thanks
This is the code for my remove button currently:
//REMOVE ROW BUTTON
JButton button2 =new JButton("Remove Row" );
buttonPanel.add( button2 );
button2.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent e){
//System.out.println("You'll never get away this time.");
System.out.println("Remove Row Button Pressed.");
int[] selected =null;
//1.Error check in case no row is selected
//2.Ask the user if they really want to remove the row
selected = table.getSelectedRows();
System.out.println("selected: " + selected[0]);
//0 = 1st row (selected), 1 = 2nd row (one below selected one). Make the number equal to the selected row
sorter.removeRow(selected[0]);
}
});//Remove Row Button
This is the error message I get:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
The code can handle it ok, and removes a row when it is selected. But I would like to be able to have a dialog box pop up and say "Please select a row to remove." And, I think it is a good programming habit to catch any errors that you can.

