Your problem is that your initial input isn't surrounded in a try catch block, so if an exception is detected, then Java throws the exception and closes the program.

The InputMismatchException is thrown when Scanner is expecting a certain data type, but gets another as its input.

e.g. if you say Scanner.nextInt() but you are given a String, then Java will throw that exception. You need to make sure that you are surrounding every statement like this with a try catch if you want to handle those exceptions.