Q:

if-statement and try-catch doesn't prevent error

this part of my code should do the following:

Check if input is a int-type (try-catch)
if input is a int, check if it is in between the list:

Code
 public static void selection(List<Performer> listperformer)
 {
  int i=0;
  List<Performer> idlist = new ArrayList<Performer>();
  Scanner sclocal = new Scanner(System.in);

  if(listperformer.isEmpty() == true)
  {
   System.out.println("- empty -");
   return; 
  }
  else
  {
   System.out.println("Enter IDs:");
   int id;
   id=sclocal.nextInt();

   while(sclocal.hasNext())
   {

    try{
     id=sclocal.nextInt();
    }catch(InputMismatchException exception)
    {
     System.out.println("Invalid input!");
    }

    if(listperformer.size() <= id || id < 0)
    {
     System.out.println("Invalid input! 294");
     return;
    }
    else
    {
     idlist.add(listperformer.get(id));
    }
    id=sclocal.nextInt();
   }
  }

doesn't work. Problem:
    1. 

if i put in a wrong ID he asks me to put in another and after this
throws an exception
if i put in a string throws an "InputMismatchException"

Let's assume, that there are only three entries in our list.
Results:
Input: 5
Output: 

Input: 4
Output: Invalid input! 294

Input: asdf
Output: Exception in thread "main" java.util.InputMismatchException...

A:

I reorganized a few of the lines, added some comments in the code, and also changed your System.out statements to reflect what is actually happening. In your catch block, the "sclocal.nextLine()" will consume the invalid input that caused the exception in the first place so that control can move forward to the next iteration.
As a general guideline, it would be a good idea to use "camelCase" for your variable names.
public static void selection(List<Performer> listperformer) {
    int i = 0;
    List<Performer> idlist = new ArrayList<Performer>();
    Scanner sclocal = new Scanner(System.in);

    if (listperformer.isEmpty() == true) {
        System.out.println("- empty -");
        return;
    } else {
        int id;//This is being used as an offset, so I recommend you rename it to "offset"
        System.out.println("Enter ID:");

        while (sclocal.hasNext()) {
            try {
                id = sclocal.nextInt();
                if (listperformer.size() <= id || id < 0) {
                    System.out.println("Invalid input! You requested the element at offset [" + id + "], but the max offset available is [" + (listperformer.size()-1) + "]. Exiting.");
                    return;
                } else {
                    System.out.println("Input is valid. We have added the offset identifier [" + id + "] to listperformer.");
                    idlist.add(listperformer.get(id));
                }
            } catch (InputMismatchException exception) {
                System.out.println("Invalid input!");
                sclocal.nextLine();//throw away the invalid input so that we can await for the next input
            }
            System.out.println("Enter ID:");
        }
    }
}

