title: Throw exception in switch statement
body: <p>This program is something simplified to what we would find in a music store. We enter the comand we want and it makes what that comand supposes to do. These are the options.</p>
  
  <ul>
  <li><p>Create "<strong>client</strong>"|"<strong>music</strong>"|"<strong>selling</strong>"</p></li>
  <li><p>List "<strong>client</strong>"|"<strong>music</strong>"|"<strong>selling</strong>"</p></li>
  <li><p>Erase "<strong>client</strong>"|"<strong>music</strong>"|"<strong>selling</strong>" (using, or without using a code that is generated when we create new statement)</p></li>
  </ul>
  
  <p>The program must execute until we type "close".</p>
  
  <p>Here I'm posting what I've done until now. </p>
  
  <p>The main question is how to throw a exception if we type wrong a comand or we type something that doesn't exist here. Now, wen this occurs it just goes back to the begining. I would apreciate too if you give me advices on any change or modification that you think could be better for the program, I'm just starting with this and I know this could be done in a better way:</p>
  
  <pre><code>public class Main {
  
      static GestionarMusica musiclist= new GestionarMusica(20);
      static GestionarCliente clientlist= new GestionarCliente(20);
  
      static Scanner input= new Scanner(System.in);
      static String instructions;
  
      public static void main (String[] args){
  
      do{
          try{
              System.out.println("Waiting for instructions: ");
              instructions= input.nextLine();
  
              switch (instructions){
                  case "create client":
                      createClient();
                      break;
                  case "create music":
                      createMusic();
                      break;
                  case "create selling":
                      //createSelling();
                      break;
  
                  case "list client":
                      listClient();
                      break;
                  case "list music":
                      listMusic();
                      break;
                  case "list selling":
                      //listSelling();
                      break;
              }
          }catch (NullPointerException npe){
              System.out.println("There are not articles on the list");
          }
  
          if (instructions.equals("erase client")){
              eraseClientWithoutCode();
          }
          if (instructions.length() &lt;= 18 &amp;&amp; instructions.length() &gt;= 17 &amp;&amp; instructions.substring(0, 16).equals("erase client")){
              String client_code = instructions.substring(16);
              client_code = client_code.trim();
              int code = Integer.parseInt(client_code);
              eraseClientWithCode(code);
          }
  
          if (instruction.equals("erase music")){
              eraseMusicWithoutCode();
          }
          if (instructions.length() &lt;= 17 &amp;&amp; instructions.length() &gt;= 16 &amp;&amp; instructions.substring(0, 15).equals("erase music")){
              String music_code = instructions.substring(15);
              music_code = music_code.trim();
              int code = Integer.parseInt(music_code);
              eraseMusicWithCode(code);
          }
  
          if (instructions.equals("erase selling")){
              eraseSellingWithoutCode();
          }
          if (instructions.length() &lt;= 16 &amp;&amp; instructions.length() &gt;= 15 &amp;&amp; instructions.substring(0, 14).equals("erase selling")){
              String selling_code = instructions.substring(14);
              selling_code = selling_code.trim();
              int code = Integer.parseInt(selling_code);
              eraseSellingWithCode(code);
          }
  
      }while(!instructions.equals("close"));
  }
  
  
  public static void createMusic() {
      System.out.println("Insert album title: ");
      String title = teclado.nextLine();
      System.out.println("Insert album autor: ");
      String autor = teclado.nextLine();
      System.out.println("Insert format: ");
      String format = input.nextLine();
  
      musiclist.add(new Music(title, autor, format, musiclist.generateCode()));
  }
  
  public static void listMusic() {
      System.out.println(musiclist.toString());
  }
  
  public static void eraseMusicWithCode(int code) {
      musiclist.delete(code);
      System.out.println("Article deleted");
  }
  
  public static void eraseMusicWithoutCode() {
      System.out.println("Insert article code: ");
      int code = input.nextInt();
      musiclist.delete(code);
      System.out.println("Article deleted");
  }
  </code></pre>
  
  <p><strong>UPDATE-- About the use of default in the switch statement</strong></p>
  
  <p>I cannot use the default because this reason. Inside the switch I have the <strong>create</strong> and <strong>list</strong> commands, but I have had to set the <strong>erase</strong> commands outside the witch because these depends on if I enter the command with the code, or without it. So, if I enter an erase command and if I have the default inside the switch, it will show the exception.</p>